<p>When you have a complex property, should you instantiate it or leave it to the user to instantiate it?</p>

<p>For example (C#)</p>

<p>A)</p>

<pre><code> class Xyz{
     List&lt;String&gt; Names {get; set;}
 }
</code></pre>

<p>When I try to use, I have to set it.</p>

<pre><code>...
Xyz xyz = new Xyz();
xyz.Name = new List&lt;String&gt;();
xyz.Name.Add("foo");
...
</code></pre>

<p>Where as if I modify the code</p>

<p>B)</p>

<pre><code> class Xyz{
     public Xyz(){
         Names = new List&lt;String&gt;();
     }
     List&lt;String&gt; Names {get; }
 }
</code></pre>

<p>which in this case, I can make the List read-only.</p>

<p>Another scenario might arise, I suppose where you would intentionally not want to set it. For example in</p>

<p>C)</p>

<pre><code> class Xyz{
     String Name {get; set;}
 }
</code></pre>

<p>I would thing it bad practice to initialize.</p>

<p>Are there some rules of thumb for such scenarios?</p>

This is my normal solution:
```
```
class XYZ 
{
   public XYZ () { Names = new List<string>(); }
   public List<string> Names { get; private set; }
}
```
```
(Note that it doesn't work with XmlSerialization, as you need getters and setters on all XmlSerialized properties.) (You can override this, but it seems like too much work for little effort).
As
OregonGhost
pointed out - you need to add
```
[XmlArray]
```
for this to work with XmlSerialization.
This still breaks the rules of encapsulation, as if you wanted to be entirely correct, you would have:
```
```
class XYZ 
{
   public XYZ () { AllNames = new List<string>(); }
   private List<string> AllNames { get; set; }
   public void AddName ( string name ) { AllNames.Add(name); }
   public IEnumerable<string> Names { get { return AllNames.AsReadOnly(); } }
}
```
```
As this goes against the design of almost all the rest of the .Net framework, I usually end up using the first solution.
However, this does have the added benefit that XYZ can track the changes to it's collection of names, and that XYZ is the only place where the collection of names can be modified.
I have implemented this for a few cases, but it causes too much friction with other programmers when I do it for everything.