Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
var array = new int[,] { //Dimensions are inferred
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6}
|
||||
}
|
||||
//Accessing a single element:
|
||||
array[0, 0] = 999;
|
||||
|
||||
//To create a 4-dimensional array with all zeroes:
|
||||
var array = new int[5, 4, 3, 2];
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
var array = new int[][] { //Dimensions are inferred
|
||||
new [] { 1, 2, 3, 4 },
|
||||
new [] { 5, 6, 7, 8, 9, 10 }
|
||||
}
|
||||
//Accessing a single element:
|
||||
array[0][0] = 999;
|
||||
|
||||
//To create a 4-dimensional array with all zeroes:
|
||||
var array = new int[5][][][];
|
||||
for (int a = 0; a < array.Length; a++) {
|
||||
array[a] = new int[4][][];
|
||||
for (int b = 0; b < array[a].Length; b++) {
|
||||
array[a][b] = new int[3][];
|
||||
for (int c = 0; c < array[a][b].Length; c++) {
|
||||
array[a][b][c] = new int[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
var array = (int[,,,])Array.CreateInstance(typeof(int), new [] { 5, 4, 3, 2 }, new [] { 10, 10, 10, 10 });
|
||||
int n = 1;
|
||||
//Note: GetUpperBound is inclusive
|
||||
for (int a = array.GetLowerBound(0); a <= array.GetUpperBound(0); a++)
|
||||
for (int b = array.GetLowerBound(1); b <= array.GetUpperBound(1); b++)
|
||||
for (int c = array.GetLowerBound(2); c <= array.GetUpperBound(2); c++)
|
||||
for (int d = array.GetLowerBound(3); d <= array.GetUpperBound(3); d++)
|
||||
array[a, b, c, d] = n++;
|
||||
|
||||
//To set the first value, we must now use the lower bounds:
|
||||
array[10, 10, 10, 10] = 999;
|
||||
//As with all arrays, Length gives the TOTAL length.
|
||||
Console.WriteLine("Length: " + array.Length);
|
||||
Console.WriteLine("First 30 elements:");
|
||||
//The multidimensional array does not implement the generic IEnumerable<int>
|
||||
//so we need to cast the elements.
|
||||
Console.WriteLine(string.Join(" ", array.Cast<int>().Take(30)) + " ...");
|
||||
Loading…
Add table
Add a link
Reference in a new issue