I am having the following code snippet where I pass a value either True or False through the PropertyValue parameter in the method declaration.
public void SetTaskInstance(String PropertyName, String PropertyValue, int row)
{
bool bValue;
try
{
PropertyName = PropertyName.ToUpper();
switch (PropertyName)
{
case "BYPASSRULESENGINE":
m_tInstance.byPassRulesEngine =
System.Boolean.TryParse(PropertyValue.ToString(), out bValue);
break;
}
Console.WriteLine("Invoking method");
}
}
If I pass True, then True is outputted. However if I pass False, the parameter False is passed through the code but once the break statement is reached and when I hover my mouse over m_tInstance.ByPassRulesEngine, I see that the bool value has become True almost magically. Why is this happening ?
The return value of TryParse indicates if the parse was successful. And of course, the value “false” or “False” is valid, so TryParse would return true. The parsed value itself is written into the
out bValueparameter.Change the line
to
All TryParse methods behave that way. So read the documentation of TryParse on MSDN here:
http://msdn.microsoft.com/en-us/library/system.boolean.tryparse.aspx