Start New Discussion within our Software Development Community

Hi Friends,
I am getting the following error with my code
"Object reference not set to instance of the object" .
My code goes as follows:

...
...
string[] isem= new string[125];
decimal[] perc = new decimal[125];
student s1=new student();
...
...
public void func()
{

isem = new string[125];
perc = new decimal[125];
string[] temproll=new string[125];
int j=0;
sem = s1.calcallperc1(..., ..., ....);//calcperc1 returns an array
j=-1;
foreach (string s in isem)
                    {
                                             
                        temproll[++j] = s.Split(' ')[0];
                        perc[j] = Convert.ToDecimal(s.Split(' ')[1]);

                    }


}
...

Please help!!

Hi Friends,
I am getting the following error with my code
"Object reference not set to instance of the object" .
My code goes as follows:

...
...
string[] isem= new string[125];
decimal[] perc = new decimal[125];
student s1=new student();
...
...
public void func()
{

isem = new string[125];
perc = new decimal[125];
string[] temproll=new string[125];
int j=0;
sem = s1.calcallperc1(..., ..., ....);//calcperc1 returns an array
j=-1;
foreach (string s in isem)
                    {
                                             
                        temproll[++j] = s.Split(' ')[0];
                        perc[j] = Convert.ToDecimal(s.Split(' ')[1]);

                    }


}
...

Please help!!

I think there is mistake in this statement

sem = s1.calcallperc1(..., ..., ....);//calcperc1 returns an array

Either it should be isem or the sem should be declared as an array variable since the function returns the an array.

Hope this would be help you!!

This article has been dead for over six months. Start a new discussion instead.