I have this code in C#. It is returning "Object reference not set to an instance of an object" exception.
Code:
public decimal Calculate(String id)
{
decimal Total=0;
AmountDataDB getData=new AmountDataDB();
List<AmountData> d = new List<AmountData>();
d = getData.Amount_Details(id);
if (d.Capacity != 0)
{
foreach (AmountData temp in d)//NullReference exception occurs here
{
Total += temp.Amount;
}
}
return Total;
}
Here, AmountDataDB and AmountData are two classes. Amount_Details returns a list of type AmountData.
if(d.capacity...)should throw the exception