-4

I'm retrieving a string value of "True" or "False". I need to convert it to 1 or 0 respectively. What's the best way to do that? Currently I'm doing it this way....

var myValue = Convert.ToInt16(Convert.ToBoolean(stringValue));

If I remove the ToBoolean part....

var myValue = Convert.ToInt16(stringValue);

.... then I get "Input string was not in a correct format" for the ToInt16 conversion. Am I doing this in the best way?

WebDevGuy2
  • 1,159
  • 1
  • 19
  • 40

1 Answers1

-2

simple if/else approach

short result = stringValue == "True" ? (short)1 : (short)0;
fubo
  • 44,811
  • 17
  • 103
  • 137