P
puzzlecracker
Is it possible, in a clean way, to convert int values too bool
int i=10;
bool b=(bool)i;
instead of doing b=(i>0);
int i=10;
bool b=(bool)i;
instead of doing b=(i>0);
Is it possible, in a clean way, to convert int values too bool
int i=10;
bool b=(bool)i;
instead of doing b=(i>0);
bool b = Convert.ToBoolean(i);
puzzlecracker said:Thanks, that's what I was looking for!
And guess how it's implemented?
public static bool ToBoolean(int value) {
return (value != 0);
}
-- Göran Andersson
_____http://www.guffa.com
puzzlecracker said:Sweet, what about the reverse?
public static int ToInt32(bool value)
{
if (!value)
{
return 0;
}
return 1;
}
?
I don't know why it is not using the ?: operator.
Did you look at the source code or use a decompiler? The MSIL doesn't
provide any distinction that a decompiler could use between an if/else vs
tertiary operator.
- Show quoted text -
Ben said:Did you look at the source code or use a decompiler? The MSIL doesn't
provide any distinction that a decompiler could use between an if/else vs
tertiary operator.