C#中各种数组的性能比较
2010-09-30 22:38:05 来源:WEB开发网交错数组实际上就是数组的数组,也就是说交错数组中的每个元素本身又是一个数组,每个嵌套数组并不要求长度一致,大家看如下代码:
int[][] arr = new int[5][];
arr[0] = new int[3];
arr[1] = new int[4];
arr[2] = new int[5];
arr[3] = new int[6];
arr[4] = new int[7];
int i=arr[3][4];
生成的IL代码如下:
.entrypoint
// 代码大小 60 (0x3c)
.maxstack 3
.locals init ([0] int32[][] arr,
[1] int32 i)
IL_0000: nop
IL_0001: ldc.i4.5
IL_0002: newarr int32[]
IL_0007: stloc.0
IL_0008: ldloc.0
IL_0009: ldc.i4.0
IL_000a: ldc.i4.3
IL_000b: newarr [mscorlib]System.Int32
IL_0010: stelem.ref
IL_0011: ldloc.0
IL_0012: ldc.i4.1
IL_0013: ldc.i4.4
IL_0014: newarr [mscorlib]System.Int32
IL_0019: stelem.ref
IL_001a: ldloc.0
IL_001b: ldc.i4.2
IL_001c: ldc.i4.5
IL_001d: newarr [mscorlib]System.Int32
IL_0022: stelem.ref
IL_0023: ldloc.0
IL_0024: ldc.i4.3
IL_0025: ldc.i4.6
IL_0026: newarr [mscorlib]System.Int32
IL_002b: stelem.ref
IL_002c: ldloc.0
IL_002d: ldc.i4.4
IL_002e: ldc.i4.7
IL_002f: newarr [mscorlib]System.Int32
IL_0034: stelem.ref
IL_0035: ldloc.0
IL_0036: ldc.i4.3
IL_0037: ldelem.ref
IL_0038: ldc.i4.4
IL_0039: ldelem.i4
IL_003a: stloc.1
IL_003b: ret
更多精彩
赞助商链接