I’m developing a windows application in C#. In my application I’ve used one static class.
Below is the code:
public static class clsNumber
{
private static object vValue;
public static object Value
{
get
{
return Value;
}
set
{
Value = value;
}
}
public static string HexValue
{
get
{
try
{
return Microsoft.VisualBasic.Conversion.Hex(vValue);
}
catch
{
return Convert.ToString(vValue);
}
}
set
{
Value = Microsoft.VisualBasic.Conversion.Val("&H" + value);
}
}
}
From another class the value of “HexValue” of the above mentioned class is being set. Below is the line of code:
iStick = sOutPut.Substring(0, 8);
clsNumber.HexValue = iStick;
While executing the above line of code the below mentioned error is coming:
"An unhandled exception of type 'System.StackOverflowException' occurred in <.....>.dll"
Can anyone please help me with the resolution to this?
Thanks in advance.
You have an non-terminating recursion here:
The line
return Valuein the getter calls the getter recursively and that leads to stack overflow. And similarly for the setter.I think you meant:
i don’t see what’s to be gained from using an explicitly named field here to back to property. I’d remove
vValueand declare the property like this: