Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Материал ориентирован скорее на сеньоров, которые занимаются хардкорной и низкоуровневой работой.
public class Test {
static final double[] vals = {
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
... // 165 строчек пропущено
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
};
}int[] ints = new int[3];
ints[0] = 1;
ints[1] = 2;
ints[2] = 3;
несоответствие поведения у mono и ms компиляторов должно быть уже привычной вещью
оригиналу статьи скоро вот уже 5 лет и пока ничего не изменилось
поведение компилятора mono, используемого в unity3d, пока-что повторяет поведение, указанное в статье
class c1
{
public int _1;
public int _2;
public int _3;
public int _4;
}
void foo()
{
new c1() { _1 = 3, _3 = 2, _2 = 1 };
}
.method private hidebysig instance void foo() cil managed
{
// Code size 31 (0x1f)
.maxstack 2
.locals init ([0] class ReflectionEmitArrayInitializerExample.Program/c1 '<>g__initLocal0')
IL_0000: nop
IL_0001: newobj instance void ReflectionEmitArrayInitializerExample.Program/c1::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldc.i4.3
IL_0009: stfld int32 ReflectionEmitArrayInitializerExample.Program/c1::_1
IL_000e: ldloc.0
IL_000f: ldc.i4.2
IL_0010: stfld int32 ReflectionEmitArrayInitializerExample.Program/c1::_3
IL_0015: ldloc.0
IL_0016: ldc.i4.1
IL_0017: stfld int32 ReflectionEmitArrayInitializerExample.Program/c1::_2
IL_001c: ldloc.0
IL_001d: pop
IL_001e: ret
} // end of method Program::foo
.method public hidebysig instance void Foo () cil managed
{
.locals init (
[0] class ClassLibrary1.Class1 c,
[1] class ClassLibrary1.Class1 '<>g__initLocal0'
)
IL_0000: nop
IL_0001: newobj instance void ClassLibrary1.Class1::.ctor()
IL_0006: stloc.1
IL_0007: ldloc.1
IL_0008: ldc.i4.3
IL_0009: stfld int32 ClassLibrary1.Class1::_1
IL_000e: ldloc.1
IL_000f: ldc.i4.1
IL_0010: stfld int32 ClassLibrary1.Class1::_2
IL_0015: ldloc.1
IL_0016: ldc.i4.2
IL_0017: stfld int32 ClassLibrary1.Class1::_3
IL_001c: ldloc.1
IL_001d: stloc.0
IL_001e: ret
}
public void Foo()
{
Class1 class1 = new Class1()
{
_1 = 3,
_2 = 1,
_3 = 2
};
}
void foo()
{
new c1() { _1 = 3, _3 = 2, _2 = 1 };
}
public void Foo()
{
Class1 class1 = new Class1()
{
_1 = 3,
_2 = 1,
_3 = 2
};
}
C#: Внутреннее строение инициализаторов массивов