Create an object array of class
I'm trying to create a class object array like this for "CruiseServerHttpClient" class
private CruiseServerHttpClient[] _cruiseManager;
for (int i=0;i<2;i++)
{
_cruiseManager[i]=new CruiseServerHttpClient();
}
Is this the right way to create the object. I get Null reference excepti开发者_C百科on on the new keyword.
BTW, I'm using VS 2010.
You need to initialize the _cruiseManager
array before setting its elements inside the loop:
_cruiseManager = new CruiseServerHttpClient[2];
for (var i = 0; i < 2; i++)
{
_cruiseManager[i] = new CruiseServerHttpClient();
}
List _cruiseManager=new List ();
_cruiseManager.Add(new CruiseServerHttpClient());
_cruiseManager.Add(new CruiseServerHttpClient());
this will do.
精彩评论