Reputation: 6540
I am facing a strange problem while running my application.
I have a class [Say studentInfo], for which I am declaring a instance above the page load [i.e. of page scope]
StudentInfo sInfo;
on Page_load I am calling this instance to call functions of that class and everything is working fine:
ex: string studentName = sInfo.GetStudentId(studentId);
But when I am writing the same above code in the different function on the same page, I am getting this error:
Object reference can not be set to null
private infoList GetInfo()
{
int studentId = // some logic;
string studentName = sInfo.GetStudentId(studentId);
}
Upvotes: 0
Views: 92
Reputation: 30111
You are declaring the variable, but not creating it
try StudentInfo sInfo = new StudentInfo ();
Upvotes: 2