Object reference not set to an instance of an object
<p>I am getting </p>

<blockquote>
  <p>Object reference not set to an instance of an object</p>
</blockquote>

<p>error when trying to call the <code>GetPersonName()</code> method in my main method. </p>

<p>Can any one explain me why this error is happening ?</p>

<p>Here is my code. Thank You</p>

<pre><code>//My Class
class Program
{
    // Main Method
    static void Main(string[] args)
    {
        DMO dmo = GetPersonName();
        Console.Write(dmo.PersonArray[0].Name);
        Console.ReadKey();
    }

    private static DMO GetPersonName()
    {
        DMO dmo = new DMO();
        dmo.PersonArray[0] = new Person { Name = "XXXXXX" }; // Object reference not set to an instance of an object.
        return dmo;
    }
}


// My Data Model Object
public class DMO
{
    private Person[] _personArray;

    public Person[] PersonArray
    {
        get { return _personArray; }
        set { _personArray = value; }
    }
}

public class Person
{
    private string _name = "";

    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
}
</code></pre>
