Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to use GetValue() method to get the value at the 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] { "aaa", "bbb", "ccc", "ddd", "eee" };

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


/*
run:
   
arr[3]: ddd
  
*/

 



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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            String[,] arr = new String[2, 4] { { "aaa", "bbb", "ccc", "ddd" }, 
                                               { "eee", "fff", "ggg", "hhh" } };

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


/*
run:
    
arr[0, 2]: ccc
arr[1, 3]: hhh
   
*/

 



answered Apr 29, 2016 by avibootz
edited Apr 29, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            String[,,] arr = new String[2, 3, 4] { { { "aaa", "bbb", "ccc", "ddd" }, { "eee", "fff", "ggg", "hhh" }, { "eee", "fff", "ggg", "hhh" } },
                                                   { { "iii", "jjj", "kkk", "lll" }, { "mmm", "nnn", "ooo", "ppp" }, { "qqq", "rrr", "sss", "ttt" } }};

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


/*
run:
   
arr[0, 2, 1]: fff
arr[1, 2, 3]: ttt
  
*/

 



answered Apr 29, 2016 by avibootz
...