Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static void Main()
       {
           int[,] a = new int[3,4];
           a[1, 1] = 10;
           int y = a[1, 1];

Now the ildasm shows me following output-
.method public hidebysig static void  Main() cil managed
{
  .entrypoint
  // Code size       29 (0x1d)
  .maxstack  4
  .locals init ([0] int32[0...,0...] a,
           [1] int32 y)
  IL_0000:  nop
  IL_0001:  ldc.i4.3
  IL_0002:  ldc.i4.4
  IL_0003:  newobj     instance void int32[0...,0...]::.ctor(int32,
                                                             int32)
  IL_0008:  stloc.0
  IL_0009:  ldloc.0
  IL_000a:  ldc.i4.1
  IL_000b:  ldc.i4.1
  IL_000c:  ldc.i4.s   10
  IL_000e:  call       instance void int32[0...,0...]::Set(int32,
                                                           int32,
                                                           int32)
  IL_0013:  ldloc.0
  IL_0014:  ldc.i4.1
  IL_0015:  ldc.i4.1
  IL_0016:  call       instance int32 int32[0...,0...]::Get(int32,
                                                            int32)
  IL_001b:  stloc.1
  IL_001c:  ret
} // end of method Class5::Main

Now see also result for three dimentionl array
public static void Main()
        {
            int[,,] a = new int[3,4,3];
            a[1, 1,2] = 10;
            int y = a[1, 1,2];
        }

Now see ildasm result
.method public hidebysig static void  Main() cil managed
{
  .entrypoint
  // Code size       32 (0x20)
  .maxstack  5
  .locals init ([0] int32[0...,0...,0...] a,
           [1] int32 y)
  IL_0000:  nop
  IL_0001:  ldc.i4.3
  IL_0002:  ldc.i4.4
  IL_0003:  ldc.i4.3
  IL_0004:  newobj     instance void int32[0...,0...,0...]::.ctor(int32,
                                                                  int32,
                                                                  int32)
  IL_0009:  stloc.0
  IL_000a:  ldloc.0
  IL_000b:  ldc.i4.1
  IL_000c:  ldc.i4.1
  IL_000d:  ldc.i4.2
  IL_000e:  ldc.i4.s   10
  IL_0010:  call       instance void int32[0...,0...,0...]::Set(int32,
                                                                int32,
                                                                int32,
                                                                int32)
  IL_0015:  ldloc.0
  IL_0016:  ldc.i4.1
  IL_0017:  ldc.i4.1
  IL_0018:  ldc.i4.2
  IL_0019:  call       instance int32 int32[0...,0...,0...]::Get(int32,
                                                                 int32,
                                                                 int32)
  IL_001e:  stloc.1
  IL_001f:  ret
} // end of method Class5::Main

Now my question is that
Is set,get,constructor of System.Array class uses params int[] as parameter
But if it is then reflection is not showing such "Set(params int[])"output in reflection.
How this result is possible?
Posted
Updated 20-Oct-12 0:57am
v3

1 solution

params is a C# specific language feature: it is seen in ILDASM as int, int, int... as ILDASM doesn't have (or need) such a construct - it is effectively an assembler language, rather than high level.
 
Share this answer
 
Comments
fdiu 20-Oct-12 7:05am    
class Class5
{
public static void Main()
{
demo d = new demo();
d.xx(1, 2, 3, 4);
}
}
class demo
{
public void xx(params int[] a)
{

}
}

Here is ildasm output:

.method public hidebysig static void Main() cil managed
{
.entrypoint
// Code size 39 (0x27)
.maxstack 4
.locals init ([0] class data_types_literals_and_variables.demo d,
[1] int32[] CS$0$0000)
IL_0000: nop
IL_0001: newobj instance void data_types_literals_and_variables.demo::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldc.i4.4
IL_0009: newarr [mscorlib]System.Int32
IL_000e: stloc.1
IL_000f: ldloc.1
IL_0010: ldc.i4.0
IL_0011: ldc.i4.1
IL_0012: stelem.i4
IL_0013: ldloc.1
IL_0014: ldc.i4.1
IL_0015: ldc.i4.2
IL_0016: stelem.i4
IL_0017: ldloc.1
IL_0018: ldc.i4.2
IL_0019: ldc.i4.3
IL_001a: stelem.i4
IL_001b: ldloc.1
IL_001c: ldc.i4.3
IL_001d: ldc.i4.4
IL_001e: stelem.i4
IL_001f: ldloc.1
IL_0020: callvirt instance void data_types_literals_and_variables.demo::xx(int32[])
IL_0025: nop
IL_0026: ret
} // end of method Class5::Main


see it shows xx(int32[]) not shows xx(int32,int32,int32,int32)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900