The following snippet of code (C# 3.5) is allowable, and gives you the benefit of unnecessary extra verbosity with the benefits of encapsulation. Of course, if you need to implement logic in your property, then you don’t want to think about automatic properties:
public T Item { get; private set; }
JP, it’s actually in C# 3.0 (and requires only .NET 2.0). Sorry for being a bore
Sean, the backing field’s name is (pseudo)randomly generated by the compiler, you shouldn’t access it using reflection.
I like this feature, it allows to keep something like DTOs very simple and short, also quickly refactorable with no multiple keystrokes. What about reflection, how that one digests automatic property backing field? normallly you shouldn’t access backing field (as any other member field) directly, but what if you have to through reflection? 10x