Object reference not set to an instance of an object [C#]

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Messages
358
Location
Hell
While running the code below I receive the following error “object reference not set to an instance of an object”, from my understanding this has to do with the initialization of objects, anyone able to see where I went wrong?

[MAIN]
m_Remote = new Remote(Count, iMachines);
System.Data.DataSet oRecs = new System.Data.DataSet();

oRecs = m_Remote.Read;
m_Remote.Setinfo(oRecs, iOIndex, iMIndex); << ERROR OCCURS HERE

[CLASS]
public class Remote
{
public object[,] m_obj;

public Remote(int iO, int iM)
{
object[,] m_obj = new object[iO, iM];
}

public System.Data.DataSet Read()
{
// Create Dataset oRecs dynamically
return oRecs;
}

public void Setinfo (System.Data.DataSet rec, int oIndex, int mIndex)
{
m_obj[oIndex, mIndex] = rec;
}
}
}
 
change
C#:
 public Remote(int iO, int iM)
{
object[,] m_obj = new object[iO, iM];
}
to
C#:
 public Remote(int iO, int iM)
{
m_obj = new object[iO, iM];
}
as you are re-declaring the array within the constructor at the moment.
 
Back
Top