Hi I have this program that I am writing that uses the struct below. I keep getting a stackoverflow error and the exception is stops the program at the fist bracket in public string sessionID set…(where the “>>>” is).
public struct SessionStruct
{
public string sessionID
{
get
{
return sessionID;
}
set
>>> {
sessionID = value;
}
}
public DateTime time
{
get
{
return time;
}
set
{
time = value;
}
}
public string type
{
get
{
return type;
}
set
{
type = value;
}
}
};
Here is the code that sets the struct:
if (type == "11" || type == "9")
{
s.sessionID = attributeArray[0].ToString();
s.time = DateTime.Now;
if (type == "9")
s.type = attributeArray[4].ToString();
}
else
{
s.sessionID = null;
s.time = DateTime.Now;
s.type = null;
}
Thanks for the help in advance…
Your property is calling itself over and over again. The property really needs a backing store to store the data in, which is typically a private variable:
Or let the compiler do it for you: