Below is my code snippet, the variable "_lastError" doesn't seem to persist after it is set then accessed elsewhere.
Can anyone give a heads up on what I missed or done incorrectly? I've debugged the program, setting a breakpoint at both the getter and the private setter. Nothing else seems to be accessing nor modifying the value of "_lastError" other than where it was intended to.
class Utils
{
private static string _lastError;
public static string LastError
{
get
{
string lastError = Utils._lastError;
Utils._lastError = string.Empty;
return lastError;
}
private set
{
Utils._lastError = value;
}
}
public static void Foo()
{
try { // .... // }
catch (Exception ex)
{
Utils.LastError = ex.Message;
}
}
}