As Jon Skeet Says :
It's unfortunate that there's no way of doing this right now. You have
to set the value in the constructor. (Using constructor chaining can
help to avoid duplication.)
Automatically implemented properties are handy right now, but could
certainly be nicer. I don't find myself wanting this sort of
initialization as often as a read-only automatically implemented
property which could only be set in the constructor and would be
backed by a read-only field. It's possible that both of these will be
fixed in C# 5, which I strongly hope will address immutability
concerns. (I don't think either of them are scheduled for C# 4.)
Source : Initializing C# auto-properties
If you need to initialize the property
without using the constructor
, you need to use a backing field
.
Example
class Demo
{
private List