You would think there would be a way using DirectCast, TryCast, CType etc but all of them seem to choke on it e.g.:
CType(\"Yes\", Boolean)
private static bool GetBool(string condition)
{
return condition.ToLower() == "yes";
}
GetBool("Yes"); // true
GetBool("No"); // false
Or another approach using extension methods
public static bool ToBoolean(this string str)
{
return str.ToLower() == "yes";
}
bool answer = "Yes".ToBoolean(); // true
bool answer = "AnythingOtherThanYes".ToBoolean(); // false