Auto properties ( {get; set;} ) have an openly inaccessible support field, which is created automatically. In fact, if you use reflection to look at the fields of a class that has an auto property, you can see that there is a private field for this property. The code below prints <Bar>k__BackingField - a strange field name, but nonetheless a field name!
I can not say that I have tried the StructLayoutAttribute properties. If it works, it certainly just applies the same logic to the backup field.
using System; using System.Reflection; namespace ConsoleApplication10 { class Program { static void Main(string[] args) { var fields = typeof(Foo).GetFields(BindingFlags.NonPublic | BindingFlags.Instance); Console.WriteLine(fields[0].Name); } } class Foo { public int Bar { get; set; } } }
source share