0

i want to create series dynamically for that i created series array objects like this

        Series[] series = new Series[10];

        series[0].Name = "Result Chart";

but while execution of program it showing object reference null error how to solve this problem

2 Answers 2

1
Series[] series = new Series[10];
series[0] = new Series();// this line is the one you missed
series[0].Name = "Result Chart";
Sign up to request clarification or add additional context in comments.

Comments

0
Series[] series = new Series[10];

This line create an array. The new is just for creating array of series.

This line puts the value at the 0th index

series[0].Name = "Result Chart";

The problem is that you have not instantiated the object at 0th index. So you need to instantiated every index which you want to use.
Like if you want to use the 0th index then you will have to use

series[0] = new Series();

or just create a loop to instantiated every index as follows

for(int i=0;i<series.Count;i++)
{
   series[i] = new Series();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.