C#中string [] []和string [,]之间有什么区别?

ehh*_*ehh 3 c# arrays string multidimensional-array

语法略有不同,但它们之间有什么区别.

public static string[][] str1 = { new string[] { Total, "N2" }};
public static string[,] str2 = { { Total, "N2" } }; 
Run Code Online (Sandbox Code Playgroud)

每种使用的准则是什么?

小智 6

看看这里:https: //msdn.microsoft.com/en-us/library/2s05feca.aspx

基本上,区别在于如何分配内存.[,]符号将在一个块中分配所有需要的内存,而[] []符号将分配一个指向数组的指针数组,其中每个数组都是单独分配的,而不一定是在其他数组旁边

  • _"一个**指针**到数组的数组"_ - 这取决于它的使用方式 - 元素可能是[单元化的](https://msdn.microsoft.com/en-us/library/2s05feca.aspx) .此外,在c#中,术语"指针"不常用,不应该是_reference_的同义词._"[锯齿状数组是一个数组数组,因此它的元素是引用类型并初始化为null](https://msdn.microsoft.com/en-us/library/2s05feca.aspx)"_ (3认同)