I have a String array
object in a class, i.e, String[] particulars
which I want to initialize during runtime. The same code segment worked for another class object which was not array though. Here nd
is an object of class.
int i=0;
foreach (DataRow row1 in dt1.Rows)
{
nd.particulars[i] = row1["floor"].ToString();
nd.quantity[i] = (double)row1["area"];
nd.rate[i] = (double)row1["rate"];
nd.amount[i] = (double)row1["amount"];
i++;
}
The following code is throwing some NullReferenceException
. The error says:
Object reference not set to an instance of an object.
The class definition is as:
class NoteDetails
{
public string[] particulars;
public double[] quantity;
public double[] rate;
public double[] amount;
public string[] mparticulars;
public double[] mquantity;
public double[] mrate;
public double[] mamount;
public NoteDetails()
{
particulars = null;
quantity = null;
amount = null;
rate = null;
mparticulars = null;
mquantity = null;
mamount = null;
mrate = null;
}
}
Please tell me what I'm doing wrong?