I’m having problems with the code below. Whenever I create a new instance of the class below and call “Select” I get an object reference not set to an instance of an object on the “this.db”
namespace SPI {
class CompaniesDB
{
private DataContainer db;
public void New() {
this.db = new DataContainer();
}
public Company Select(int companyID) {
return this.db.Company_Get(companyID).SingleOrDefault();
}
}
}
Can someone point me at why my “New()” doesn’t seem to be creating a new object?
I’m relatively new to C#.
You don’t name a constructor as
New. You name it with the class Name.Try
MSDN page on constructors: http://msdn.microsoft.com/en-us/library/ms173115.aspx