ale w tle działa to zupełnie inaczej.
Ok, get/set dla zwyklych wlasciwosci:
.method public hidebysig specialname
instance default int32 get_Age1 () cil managed
{
// Method begins at RVA 0x2050
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 Person::_age1
IL_0006: ret
} // end of method Person::get_Age1
// method line 2
.method public hidebysig specialname
instance default void set_Age1 (int32 'value') cil managed
{
// Method begins at RVA 0x2058
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld int32 Person::_age1
IL_0007: ret
} // end of method Person::set_Age1
Dla automatycznych:
.method public hidebysig specialname
instance default int32 get_Age2 () cil managed
{
.custom instance void class [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
// Method begins at RVA 0x2061
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 Person::'<Age2>k__BackingField'
IL_0006: ret
} // end of method Person::get_Age2
// method line 4
.method public hidebysig specialname
instance default void set_Age2 (int32 'value') cil managed
{
.custom instance void class [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
// Method begins at RVA 0x2069
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld int32 Person::'<Age2>k__BackingField'
IL_0007: ret
} // end of method Person::set_Age2
W dzialaniu obu metod nie ma zadnej roznicy, poza tym, ze automatycznie maja zrozumialy atrybut.
Properties muszą być inicjalizowane w przeciwieństwie do zwykłych zmiennych.
Przez kogo musza byc inicjalizowane? https://ideone.com/6PE9fv