How to use Array.SetValue() method to set a value to element at specified position in 1D, 2D and 3D Array in C#

3 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] arr = new String[5];

            arr.SetValue("two", 2);
            Console.WriteLine("arr[2]: {0}", arr.GetValue(2));
        }
    }
}


/*
run:
    
arr[2]: two
   
*/

 



answered Apr 30, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            String[,] arr2D = new String[5, 6];

            arr2D.SetValue("two-three", 2, 3);
            Console.WriteLine("arr2D[2,3]: {0}", arr2D.GetValue(2, 3));
        }
    }
}


/*
run:
    
arr2D[2,3]: two-three
   
*/

 



answered Apr 30, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            String[,,] arr3D = new String[6, 5, 4];

            arr3D.SetValue("one-two-three", 1, 2, 3);
            Console.WriteLine("arr3D[1,2,3]: {0}", arr3D.GetValue(1, 2, 3));
        }
    }
}


/*
run:
    
arr3D[1,2,3]: one-two-three
   
*/

 



answered Apr 30, 2016 by avibootz
...