Как получить доступ к строке двумерного массива в C#? Я хочу получить счет строки i.C# Доступ к строке в двумерном массиве
Спасибо!
Как получить доступ к строке двумерного массива в C#? Я хочу получить счет строки i.C# Доступ к строке в двумерном массиве
Спасибо!
Вопрос действительно зависит от того, какой тип 2D-массива вы думаете и какова размерная строка.
Правильное 2D массив
// Init
var arr = new int[5,10];
// Counts
arr.GetLength(0) // Length of first dimension: 5
arr.GetLength(1) // Length of second dimension: 10
Jagged "2D" массив
// Init
var arr = new int[3][];
// Initially arr[0],arr[1],arr[2] is null, so we have to intialize them:
arr[0] = new int[5];
arr[1] = new int[4];
arr[2] = new int[2];
// Counts
arr.Length // Length of first dimension
// In this case the "second dimension" (if you can call it that) is of variable size
arr[0].Length // Length: 5
arr[1].Length // Length: 4
arr[2].Length // Length: 2
Спасибо, 2d массивы очень разные в C# – CodeKingPlusPlus
@CodeKingPlusPlus Добро пожаловать :-) –
Это также будет работать,
string[,] a = new string[,]
{
{"ant", "aunt"},
{"Sam", "Samantha"},
{"clozapine", "quetiapine"},
{"flomax", "volmax"},
{"toradol", "tramadol"}
};
// a[1,1] is equal to Samantha
Это хороший ресурс:> [HTTP : //www.dotnetperls.com/2d-array] (HTTP: //www.dotnetperls .com/2d-array) – Bit