Hi, So that can we use one instead of the other at the same time? I mean can we use bool in one place and boolean in another place? Why bool comes in dark blue and boolean comes in light blue as if it is something user-defined? Can someone help? Thanks in advance Regards, JayaniThursday, April 02, 2009 12:20 PM
Yes, you can use bool or Boolean... it's the same. Although consistency is important, and you should use bool.
The reason bool comes in dark blue is because it is a C# keyword, and Boolean in light blue is because it's a type (framework types and user-defined types are shown in the same color).
/* No comments */Thursday, April 02, 2009 12:24 PM
Hi, So that can we use one instead of the other at the same time? I mean can we use bool in one place and boolean in another place? Why bool comes in dark blue and boolean comes in light blue as if it is something user-defined? Can someone help? Thanks in advance Regards, Jayani
The reason why "bool" is in dark blue and "Boolean" is in light blue is that "Boolean" is the actual type name, while "bool" is the keyword in C# that is an alias for this type. All C# keywords are in dark blue, and all class names are in light blue.
You can use both interchangeably if you'd like. It won't cause any performance implications, and the compiled code will look exactly the same, but it would be better practice to pick one or the other and use it consistently across your entire application. I've heard good reasons to use "bool" and good reasons to use "Boolean", but regardless of whose reasons you subscribe to, be consistent.
David Morton - http://blog.davemorton.net/Thursday, April 02, 2009 1:46 PMModerator
Maybe it will hit 1000 views, too. There is a difference when it comes which Framework that you are targeting. But, the difference is under the hood and should not affect code compilation or cause run time exceptions.
Iwould seem that the Compact Framework does a switcheroo on the type Boolean and the keyword bool.
The Compact FCL uses 8 bits for a boolean, while the full-blown FCL uses 32 bits.
While this behavior is the same on the full .NET Framework, the .NET Compact Framework also includes
stringin C#), and
boolin C#) as blittable types. In the case of
System.String,this is due to the fact that, as mentioned previously, the .NET Compact Framework only supports Unicode, and so the marshaler always marshals the former as a 2-byte Unicode char and the latter as a Unicode array. In the case of
System.Boolean, the .NET Compact Framework marshaler uses a 1-byte integer value, whereas the full .NET framework uses a 4-byte integer value.
Mark the best replies as answers. "Fooling computers since 1971."Thursday, April 02, 2009 4:13 PMModerator