'System.NullReferenceException
<p>I dont Know what the problem is, the error which it gives is the following : </p>

<blockquote>
  <p>An unhandled exception of type 'System.NullReferenceException'
  occurred in AlgoAssignment.exe Additional information: Object
  reference not set to an instance of an object.</p>
</blockquote>

<p>This is the Code : </p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace AlgoAssignment
{
    class person
    {
        static int id;
        public List&lt;string&gt; prefrence { get; set; }
        public string name { get; set; }
        public string engagedTo;
        public void setName(string a) { this.name = a; }
        public void setPrefrence(string a)
        {
            this.prefrence.Add(a);
    }
    public person()
    {
        id++;
        name = null;
        engagedTo = null;

    }
    public void displayInfo()
    {
        Console.Write("Name : " + this.name + "\n");
        Console.Write(this.prefrence);

    }

}
class Program
{
    static void Main(string[] args)
    {
        string fileName = "A1P2in1a.txt";
        StreamReader sr = new StreamReader(fileName);
        string no = sr.ReadLine();      // total use cases
        int n = int.Parse(no);
        sr.ReadLine();


        person[] pr = new person[n];


        for (int i = 0; i &lt; n; i++)
        {
            string newLine = sr.ReadLine();
            string[] parts = newLine.Split(' ');
            parts[0] = parts[0].Replace(":", "");
            pr[i].setName(parts[0]);
            for (int j = 1; j &lt; n; j++)
            {
                pr[i].setPrefrence(parts[j]);
            }
        }

        for (int i = 0; i &lt; n; i++)
        {
            pr[i].displayInfo();
        }


        Console.ReadKey();



    }
}
</code></pre>

<p>}</p>
