Others have posted that they are not the same, and they are correct. I'm going to go a little further in to some low level detail though, and show you the IL (Intermediate Language) code generated for each version by the compiler.
Public getter, private setter vs public getter
The public getter, and private setter:
public class Test1
{
public int MyProperty { get; private set; }
}
Generates:
Test1.get_MyProperty:
IL_0000: ldarg.0
IL_0001: ldfld UserQuery+Test1.<MyProperty>k__BackingField
IL_0006: ret
Test1.set_MyProperty:
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld UserQuery+Test1.<MyProperty>k__BackingField
IL_0007: ret
Test1..ctor:
IL_0000: ldarg.0
IL_0001: call System.Object..ctor
IL_0006: nop
IL_0007: ret
The version with only the getter:
public class Test2
{
public int MyProperty { get; }
}
Generates:
Test2.get_MyProperty:
IL_0000: ldarg.0
IL_0001: ldfld UserQuery+Test2.<MyProperty>k__BackingField
IL_0006: ret
Test2..ctor:
IL_0000: ldarg.0
IL_0001: call System.Object..ctor
IL_0006: nop
IL_0007: ret
Public getter vs Expression-Body getter
Getter only:
public class Test1
{
public int MyProperty => 123;
}
Generates:
Test1.get_MyProperty:
IL_0000: ldc.i4.s 7B
IL_0002: ret
Test1..ctor:
IL_0000: ldarg.0
IL_0001: call System.Object..ctor
IL_0006: nop
IL_0007: ret
Expression-Body getter:
public class Test2
{
public int MyProperty { get; } = 123;
}
Generates:
Test2.get_MyProperty:
IL_0000: ldarg.0
IL_0001: ldfld UserQuery+Test2.<MyProperty>k__BackingField
IL_0006: ret
Test2..ctor:
IL_0000: ldarg.0
IL_0001: ldc.i4.s 7B
IL_0003: stfld UserQuery+Test2.<MyProperty>k__BackingField
IL_0008: ldarg.0
IL_0009: call System.Object..ctor
IL_000E: nop
IL_000F: ret
As you can see, all 4 of these generate very different results behind the scenes at the IL level.
Depending on the compiler optimization settings, these could be different. The compile could choose to remove the backing field if it sees nothing uses it. It could also do the same for an unused private setter.
It is also possible that they may be jitted (just-int-time compilation) differently as the run-time processes them.