Last active
March 27, 2019 04:25
-
-
Save binki/f108ad6f5ec2c48d6e7ffef578fa5b8f to your computer and use it in GitHub Desktop.
MultiDimensionalArray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace MultiDimensionArray | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var x = new int[2, 3]; | |
UseArray(x); | |
} | |
static void UseArray(int[,] x) | |
{ | |
Console.WriteLine(x.GetLength(1)); // 3 | |
Console.WriteLine(x[x.GetLength(0) - 1, x.GetLength(1) - 1]); // 0 | |
{ | |
var index0 = 0; | |
var index1 = x.GetLength(1) - 1; | |
x[index0, index1] = 2; | |
Console.WriteLine(x[index0, index1]); // 2 | |
} | |
// 00 | |
// 00 | |
// 20 | |
for(var index1 = 0; index1 < x.GetLength(1); index1++) | |
{ | |
for(var index0 = 0; index0 < x.GetLength(0); index0++) | |
{ | |
Console.Write(x[index0, index1]); | |
} | |
Console.WriteLine(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment