Re: Cannot convert type 'int' to 'bool'

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Fri, 21 Sep 2007 21:39:26 -0700, John <no@xxxxxxxx> wrote:

The following code:

int test = 1;
bool isTrue = (bool)test;

results in a compiler error:

Cannot convert type 'int' to 'bool'

wtf, any ideas on how to work around this?

bool isTrue = Convert.ToBoolean(test);

You will find that non-zero integer arguments to Convert.ToBoolean all
return true.

regards
A.G.
.



Relevant Pages

  • Cannot convert type int to bool
    ... bool isTrue = test; ... results in a compiler error: ... wtf, any ideas on how to work around this? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Cannot convert type int to bool
    ... results in a compiler error: ... Cannot convert type 'int' to 'bool' ... wtf, any ideas on how to work around this? ...
    (microsoft.public.dotnet.languages.csharp)