Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere can I find information on the Get, Set and Address methods for multidimensional System.Array instances in .NET?
    text
    copied!<p><a href="http://msdn.microsoft.com/en-us/library/system.array.aspx" rel="nofollow noreferrer">System.Array</a> serves as the base class for all arrays in the Common Language Runtime (CLR). According to <a href="http://blogs.msdn.com/haibo_luo/archive/2006/11/26/1157785.aspx" rel="nofollow noreferrer" title="Late-bound array SetValue">this article</a>:</p> <blockquote> <p>For each concrete array type, [the] runtime adds three special methods: <code>Get</code>/<code>Set</code>/<code>Address</code>.</p> </blockquote> <p>and indeed if I disassemble this C# code,</p> <pre><code>int[,] x = new int[1024,1024]; x[0,0] = 1; x[1,1] = 2; x[2,2] = 3; Console.WriteLine(x[0,0]); Console.WriteLine(x[1,1]); Console.WriteLine(x[2,2]); </code></pre> <p>into CIL I get,</p> <pre><code>IL_0000: ldc.i4 0x400 IL_0005: ldc.i4 0x400 IL_000a: newobj instance void int32[0...,0...]::.ctor(int32, int32) IL_000f: stloc.0 IL_0010: ldloc.0 IL_0011: ldc.i4.0 IL_0012: ldc.i4.0 IL_0013: ldc.i4.1 IL_0014: call instance void int32[0...,0...]::Set(int32, int32, int32) IL_0019: ldloc.0 IL_001a: ldc.i4.1 IL_001b: ldc.i4.1 IL_001c: ldc.i4.2 IL_001d: call instance void int32[0...,0...]::Set(int32, int32, int32) IL_0022: ldloc.0 IL_0023: ldc.i4.2 IL_0024: ldc.i4.2 IL_0025: ldc.i4.3 IL_0026: call instance void int32[0...,0...]::Set(int32, int32, int32) IL_002b: ldloc.0 IL_002c: ldc.i4.0 IL_002d: ldc.i4.0 IL_002e: call instance int32 int32[0...,0...]::Get(int32, int32) IL_0033: call void [mscorlib]System.Console::WriteLine(int32) IL_0038: ldloc.0 IL_0039: ldc.i4.1 IL_003a: ldc.i4.1 IL_003b: call instance int32 int32[0...,0...]::Get(int32, int32) IL_0040: call void [mscorlib]System.Console::WriteLine(int32) IL_0045: ldloc.0 IL_0046: ldc.i4.2 IL_0047: ldc.i4.2 IL_0048: call instance int32 int32[0...,0...]::Get(int32, int32) IL_004d: call void [mscorlib]System.Console::WriteLine(int32) </code></pre> <p>where the calls to the aforementioned <code>Get</code> and <code>Set</code> methods can be clearly seen. It seems the arity of these methods is related to the dimensionality of the array, which is presumably why they are created by the runtime and are not pre-declared. I couldn't locate any information about these methods on MSDN and their simple names makes them resistant to Googling. I'm writing a compiler for a language which supports multidimensional arrays, so I'd like to find some official documentation about these methods, under what conditions I can expect them to exist and what I can expect their signatures to be.</p> <p>In particular, I'd like to know whether its possible to get a <code>MethodInfo</code> object for <code>Get</code> or <code>Set</code> for use with <code>Reflection.Emit</code> without having to create an <em>instance</em> of the array with correct type and dimensionality on which to reflect, as is done in the linked example.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload