Hi, I have a problem with VS2010beta2 and .NET Framework Client Profile, although I would expect the problem to be something to do with my inexperienced coding. I have this block of code..
struct sGamePort
{
public string sgpProtocol;
public UInt16 sgpPortStart;
public UInt16 sgpPortEnd;
}
struct sGamePortItem
{
public string sgpName;
public List<sGamePort> sgpPortList;
}
List<sGamePortItem> sGames;
private sGamePort ParsePorts(string\[\] line)
{
sGamePort gp = new sGamePort();
gp.sgpProtocol = line\[0\];
int num = line.Count();
if (num == 2)
{
// single port opened...
gp.sgpPortStart = Convert.ToUInt16(line\[1\]);
gp.sgpPortEnd = Convert.ToUInt16(line\[1\]);
}
if (num == 3)
{
// port range opened...
gp.sgpPortStart = Convert.ToUInt16(line\[1\]);
gp.sgpPortEnd = Convert.ToUInt16(line\[2\]);
}
return gp;
}
Where line is a string array which essentially holds some tokens. ie. line[0] = "NAME" line[1] = "JOHN" line[2] = "YOUNG" Now, in a seperate function I have
sGamePortItem pi = new sGamePortItem();
pi.sgpProtocol = "TCP";
pi.sgpPortList.Add(ParsePorts(strCMD));
This gives me a Null Reference Exception, so I changed it to this...
sGamePortItem pi = new sGamePortItem();
pi.sgpProtocol = "TCP";
sGamePort test = new sGamePort();
test = ParsePorts(strCMD);
pi.sgpPortList.Add(test); // ERROR HERE
Now, the error only occurs on the specified line above.. What am I doing wrong? Is it to do with me using the new keyword incorrectly? Or do I not use 'new'? Any help would be appreciated as this has been confusing me for a few hours now, lol Thanks again. John
Yippee Kai Yai Signed Polomint.......