Question

This is my code

var dictionary = new Dictionary<string, List<Int64[][]>>();
for (int i = 0; i < compainNames.Count(); i++)
{
    List<Int64[][]> data = new List<Int64[][]>();
    var dataForOneCampaint = DTgraph.Select("Campaign = '" + compainNames[i].CampaignName.ToString() +"'").ToList();
    for (int j = 0; j < dataForOneCampaint.Count(); j++)
    {
        Int64[][] array = new Int64[1][];
        array[0][0] = (Int64)dataForOneCampaint[j].Field<Decimal>("Inb.ServiceLevel");
        DateTime d = DateTime.Parse(dataForOneCampaint[j].Field<string>("Date").ToString());
        array[0][1] = d.Ticks;
        data.Add(array);
    }
    dictionary.Add(compainNames[i].ToString(), data);
}

where DTgraph is a datatable.

I got this exception {"Object reference not set to an instance of an object."}

on this line : array[0][0] = (Int64)dataForOneCampaint[j].Field<Decimal>("Inb.ServiceLevel");

I can see that the dataForOneCampaint has 16 values.

and I have used the same field Inb.ServiceLevel in another function exactly like I did in this code and It works fine.

where am I making wrong please?

Was it helpful?

Solution

Jagged array initialization have to be performed twice: once for outer dimension and once for each inner array. It's described more precisely on MSDN: Jagged Arrays (C# Programming Guide).

In your case you should do following:

Int64[][] array = new Int64[1][];
array[0] = new Int64[2];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top