What's the magic of arrays in C#

后端 未结 8 1083
生来不讨喜
生来不讨喜 2020-12-09 08:56
int[] a = new int[5];
string[] b = new string[1];

The types of both a and b inherit from the abstract System.Array<

8条回答
  •  無奈伤痛
    2020-12-09 09:44

    Arrays are special to CLR. They're allocated with 'newarr' instruction, and elements are accessed with 'ldelem*' and 'stelem*' instructions, not via System.Array methods;

    see http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.newarr.aspx

    You can check out ildasm output to see how arrays are represented.

    So, to answer your question - no new type declaration is generated for any particular array.

提交回复
热议问题