net*_*net 16 c# arrays multidimensional-array
可能重复:
C#中多维数组和数组数组之间的区别是什么?
任何人都可以解释我的区别string[][]和string[,]?
string[,]- 多维Arrary(矩形阵列)
多维可以有多个维度.以下示例显示如何创建两行和两列的二维数组.
宣言 :
string[,] contacts;
Run Code Online (Sandbox Code Playgroud)
实例:
string[,] contacts = new string[2,2];
Run Code Online (Sandbox Code Playgroud)
初始化:
string[,] contacts = new string[2, 2] { {"John Doe","johndoe@example.com"}, {"Jane Doe","janedoe@example.com"} };
Run Code Online (Sandbox Code Playgroud)
string[ ][ ]- 锯齿状阵列(阵列阵列)
锯齿状数组是一个数组,其元素是数组.锯齿状阵列的元素可以具有不同的尺寸和大小.锯齿状数组有时被称为"数组数组".
锯齿状阵列可以有效地存储许多不同长度的行.可以使用任何类型的数据,参考或值.索引锯齿状阵列很快.分配它们有点慢.
锯齿状数组比多维数组更快
宣言 :
string[][] contacts;
Run Code Online (Sandbox Code Playgroud)
实例:
string[][] contacts = new string[2][];
for (int i = 0; i < contacts.Length; i++)
{
contacts[i] = new string[3];
}
Run Code Online (Sandbox Code Playgroud)
初始化:
string[][] contacts = new string[2][] { new string[] {"john@example.com","johndoe@example.com"}, new string[] {"janedoe@example.com","jane@example.com","doe@example.com"} };
Run Code Online (Sandbox Code Playgroud)