;
> Thanks,
> Mike
>
>
> On 8/3/06, Chris Anderson <[EMAIL PROTECTED]> wrote:
> >
> > bool x = (value != 0);
> >
> >
> > > -Original Message-
> > > From: Discussion of advanced .NET topics.
> > > [mailt
ggestions how I can revise my code to allow for nullable
types, I'd like to see it.
Thanks,
Mike
On 8/3/06, Chris Anderson <[EMAIL PROTECTED]> wrote:
>
> bool x = (value != 0);
>
>
> > -Original Message-
> > From: Discussion of advanced .NET topics.
&
ke to see it.
Thanks,
Mike
On 8/3/06, Chris Anderson <[EMAIL PROTECTED]> wrote:
bool x = (value != 0);
> -Original Message-
> From: Discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] On Behalf Of Mike Andrews
> Sent: 03 August 2006 14:16
> To: ADVANCED-
Can anyone tell me any good reason why the C# compiler will not allow
casting an int to a bool?
0) Because a bool is not an int (and a System.Boolean is not a
System.Int32 etc...)
1) To resolve the ambiguity about what value true is (e.g. -1,
non-zero, whatever).
2) To prevent stupidity like the
Can anyone tell me any good reason why the C# compiler will not allow
casting an int to a bool?
What's the mapping of integers to boolean values?
If you're a C (C++) programmer, you'll say
0 -> false
!0 -> true
and consider the answer blindingly obvious.
The question would be less obvious to a
> Can anyone tell me any good reason why the C# compiler will
> not allow casting an int to a bool?
because a bool isn't an int? :) It's not C++ ;)
FB
>
> example:
>
> bool x = (bool)1;
>
>
> instead of doing something like this:
> bool x = Convert.ToBoolean(1);
> or
> bo
bool x = (value != 0);
> -Original Message-
> From: Discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] On Behalf Of Mike Andrews
> Sent: 03 August 2006 14:16
> To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> Subject: [ADVANCED-DOTNET] Gripe out the C# com
-DOTNET] Gripe out the C# compiler...
Guys,
Can anyone tell me any good reason why the C# compiler will not allow
casting an int to a bool?
example:
bool x = (bool)1;
instead of doing something like this:
bool x = Convert.ToBoolean(1);
or
bool x = bool.Parse(1);
Makes it very difficult to write
Guys,
Can anyone tell me any good reason why the C# compiler will not allow
casting an int to a bool?
example:
bool x = (bool)1;
instead of doing something like this:
bool x = Convert.ToBoolean(1);
or
bool x = bool.Parse(1);
Makes it very difficult to write generic methods where I need to ca