C# 字符串[]在C中是什么意思?

C# 字符串[]在C中是什么意思?,c#,C#,例如 字符串数组的数组 它读取一个文件并创建一个数组,其中每个元素都是文件中的一行,由通过在逗号处拆分该行而创建的字符串数组表示 所以像这样的文件 String [ ][ ] LinesSplitByComma1 = File.ReadAllLines("Filepath").Select(s => s.Split(',')).ToArray(); 将被代表为 a,b,c 1,2,3 asdas,ertert,xcvxcvx 这是一个字符串数组数组。在您的特定情况下,您有一个行

例如


字符串数组的数组

它读取一个文件并创建一个数组,其中每个元素都是文件中的一行,由通过在逗号处拆分该行而创建的字符串数组表示

所以像这样的文件

String [ ][ ] LinesSplitByComma1 =
    File.ReadAllLines("Filepath").Select(s => s.Split(',')).ToArray();
将被代表为

a,b,c
1,2,3
asdas,ertert,xcvxcvx

这是一个字符串数组数组。在您的特定情况下,您有一个行数组,每个行被拆分为一个逗号分隔的标记数组

LinesSplitByComma1[0][0] = "a"
LinesSplitByComma1[0][1] = "b"
LinesSplitByComma1[0][2] = "c"
LinesSplitByComma1[1][0] = "1"
LinesSplitByComma1[1][1] = "2"
LinesSplitByComma1[1][2] = "3"
LinesSplitByComma1[2][0] = "asdas"
LinesSplitByComma1[2][1] = "ertert"
LinesSplitByComma1[2][2] = "xcvxcvx"

这是一个锯齿状阵列;字符串数组的数组。它是二维阵列的一种形式;另一个是矩形数组,可以像字符串[,]一样声明

区别在于名称本身;锯齿状数组的子数组可以有不同数量的值,而矩形数组的子数组长度相同

在记忆中,它们看起来非常不同。锯齿状数组最初是作为指向其他数组的指针数组创建的,当锯齿状数组初始化时,构成构造的第二维度的数组将分别在第一维度数组的存储桶中创建和引用:

string[][] lines  = File.ReadAllLines("Filepath").Select(s => s.Split(',')).ToArray();
string[]   tokens = lines[i];
string     token  = tokens[j];
但是,矩形阵列作为单个内存块一次性创建:

string[][] jaggedArray = new string[3][]; //the first dimension contains three elements
jaggedArray[0] = new string[5]; //now the first element is an array of 5 elements.
jaggedArray[1] = new string[4]; //the second element's array can be a different length.
jaggedArray[0][2] = "Test";
var secondDim = jaggedArray[1]; //A higher-dimension array of a jagged array can be independently referenced.
string[,] rectArray = new string[3,5]; //the entire 3x5 block of string refs is now reserved.
rectArray[0,4] = "Test"; //we didn't have to declare the second-dimension array.
//However, the following will not compile:
var secondDim = rectArray[1]; //a rectangular array's higher dimensions can't be "severed".