c# - Insert values for all 2nd columns of a 1st column of a 2D array -
c# - Insert values for all 2nd columns of a 1st column of a 2D array -
i'm trying question says. (it might confusing) here code should create understand i'm trying do.
classes = new string[14, 5]; classes[0] = {"value1 [0, 0]", "value2 [0, 1]", "value3 [0, 2]", "value4 [0, 3]", "value5 [0, 4]"};
some languages or environments(like matlab) allow such things work, c# doesn't provide such access rectangular arrays string[x, y].
with such arrays should alter each element individually:
string[,] classes = new string[14, 5];classes = new string[14, 5]; int32 rowtochange = 0; for(int32 col = 0; col < classes.getlength(1); col++) { classes[rowtochange, col] = string.format("value{0} [{1}. {0}]", rowtochange , col ); }
but utilize jagged arrays : string[][]
string[][] classes = new string[14][]; int32 rowtochange = 0; classes[rowtochange] = new string[]{"value1 [0, 0]", "value2 [0, 1]", "value3 [0, 2]", "value4 [0, 3]", "value5 [0, 4]"};
you read what differences between multidimensional array , array of arrays in c#? understand differences
c# multidimensional-array
Comments
Post a Comment