Unterschied zwischen Aufrufinstanz und newobj-Instanz in AWL
Ich beschäftige mich eingehend mit C # und spiele mit nullbaren Werttypen. Nur zu Versuchszwecken habe ich ein Stück Code geschrieben:
private static void HowNullableWorks()
{
int test = 3;
int? implicitConversion = test;
Nullable<int> test2 = new Nullable<int>(3);
MethodThatTakesNullableInt(null);
MethodThatTakesNullableInt(39);
}
Und ich durfte das sehenimplicitConversion / test2 Variablen werden initialisiert mit:
call instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
Unterricht, während, wennMethodThatTakesNullableInt heißt ich kann sehen:
IL_0017: initobj valuetype [mscorlib]System.Nullable`1<int32>
und
IL_0026: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
was ich verstehe. Ich dachte, dass ich sehen werdenewobj Anleitung fürimplicitConversion / test2 auch.
Dies ist der vollständige IL-Code:
.method private hidebysig static void HowNullableWorks() cil managed
{
// Code size 50 (0x32)
.maxstack 2
.locals init ([0] int32 test,
[1] valuetype [mscorlib]System.Nullable`1<int32> implicitConversion,
[2] valuetype [mscorlib]System.Nullable`1<int32> test2,
[3] valuetype [mscorlib]System.Nullable`1<int32> CSIch beschäftige mich eingehend mit C # und spiele mit nullbaren Werttypen. Nur zu Versuchszwecken habe ich ein Stück Code geschrieben:0000)
IL_0000: nop
IL_0001: ldc.i4.3
IL_0002: stloc.0
IL_0003: ldloca.s implicitConversion
IL_0005: ldloc.0
IL_0006: call instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_000b: nop
IL_000c: ldloca.s test2
IL_000e: ldc.i4.3
IL_000f: call instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_0014: nop
IL_0015: ldloca.s CSIch beschäftige mich eingehend mit C # und spiele mit nullbaren Werttypen. Nur zu Versuchszwecken habe ich ein Stück Code geschrieben:0000
IL_0017: initobj valuetype [mscorlib]System.Nullable`1<int32>
IL_001d: ldloc.3
IL_001e: call void csharp.in.depth._2nd.Program::MethodThatTakesNullableInt(valuetype [mscorlib]System.Nullable`1<int32>)
IL_0023: nop
IL_0024: ldc.i4.s 39
IL_0026: newobj instance void valuetype [mscorlib]System.Nullable`1<int32>::.ctor(!0)
IL_002b: call void csharp.in.depth._2nd.Program::MethodThatTakesNullableInt(valuetype [mscorlib]System.Nullable`1<int32>)
IL_0030: nop
IL_0031: ret
} // end of method Program::HowNullableWorks