Last Updated : 12 Jul, 2025
Array.GetValue() Method in C# is used to gets the value of the specified element in the current
Array. There are total 8 methods in the overload list of this method which are as follows:
Here, we are explaining the first two methods i.e. Array.GetValue(Int32, Int32) and Array.GetValue(Int64, Int64) method.
GetValue(Int32, Int32) methodis used to get the value at the specified position in the two-dimensional Array. The indexes are specified as 32-bit integers.
Syntax:public object GetValue (int index1, int index2);
Here,
This method returns the element at the specified index define by the passed parameters in the 2D array.
Exceptions:is used to get the value at the specified position in the two-dimensional Array. The indexes are specified as 64-bit integers.
Syntax:public object GetValue (long index1, long index2);
Here,
This method returns the element at the specified index define by the passed parameters in the 2D array.
Exceptions:
// C# program to demonstrate Array.GetValue(Int32, Int32)
// and array.GetValue(Int64 , Int64) method
using System;
public class GFG {
public static void Main()
{
// declare a character array
char[,] arr = new char[3,2]
{
{ 'A', 'B' },
{ 'C', 'D' },
{ 'E', 'F' }
};
// using GetValue(Int32, Int32) and
// GetValue(Int64, Int64) method
Console.WriteLine("element at index [0,0] is : " + arr.GetValue(0,0));
Console.WriteLine("element at index [1,1] is : " + arr.GetValue(1,1));
Console.WriteLine("element at index [0,1] is : " + arr.GetValue(0,1));
Console.WriteLine("element at index [1,0] is : " + arr.GetValue(1,0));
Console.WriteLine("element at index [2,0] is : " + arr.GetValue(2,0));
Console.WriteLine("element at index [2,1] is : " + arr.GetValue(2,1));
}
}
Output:
element at index [0,0] is : A element at index [1,1] is : D element at index [0,1] is : B element at index [1,0] is : C element at index [2,0] is : E element at index [2,1] is : FExample 2: csharp
// C# program to demonstrate Array.GetValue(Int32, Int32)
// and array.GetValue(Int64 , Int64) method
using System;
public class GFG {
public static void Main()
{
// declare a string array
string[,] arr = new string[3,2];
// use "SetValue()" method to set
// the value at specified index
arr.SetValue( "C++", 0, 0 );
arr.SetValue( "Java", 0, 1 );
arr.SetValue( "C#", 1, 0 );
arr.SetValue( "Perl", 1, 1 );
arr.SetValue( "Python", 2, 0 );
arr.SetValue( "PHP", 2, 1 );
/*the array look like
| C++ | | Java|
| C# | | Perl|
| python| | PHP |
*/
// Using GetValue(Int32, Int32) and
// GetValue(Int64, Int64) method
Console.WriteLine("element at index [0,0] is : " + arr.GetValue(0,0));
Console.WriteLine("element at index [1,1] is : " + arr.GetValue(1,1));
Console.WriteLine("element at index [0,1] is : " + arr.GetValue(0,1));
Console.WriteLine("element at index [1,0] is : " + arr.GetValue(1,0));
Console.WriteLine("element at index [2,0] is : " + arr.GetValue(2,0));
Console.WriteLine("element at index [2,1] is : " + arr.GetValue(2,1));
}
}
Output:
element at index [0, 0] is : C++ element at index [1, 1] is : Perl element at index [0, 1] is : Java element at index [1, 0] is : C# element at index [2, 0] is : Python element at index [2, 1] is : PHPNote:
For online compiler it is not possible to use 32-bit or 64-bit integer. Use offline compiler for 32 or 64-bit integer.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4