C# List + Object reference not set to an instance of an object
<p>I have this code in C#.
It is returning "Object reference not set to an instance of an object" exception.</p>

<p>Code:</p>

<pre><code>    public decimal Calculate(String id)
    {
        decimal Total=0;
        AmountDataDB getData=new AmountDataDB();
        List&lt;AmountData&gt; d = new List&lt;AmountData&gt;();
        d = getData.Amount_Details(id);
        if (d.Capacity != 0)
        {
            foreach (AmountData temp in d)//NullReference exception occurs here
            {
                Total += temp.Amount;
            }

        }
        return Total;
    }
</code></pre>

<p>Here, AmountDataDB and AmountData are two classes. Amount_Details returns a list of type AmountData.</p>
