Boolean values: Difference between revisions

m
C# Removed the remark about C#8 nullable types because it does not apply to bool.
m (→‎{{header|Phix}}: conversely not "=true")
m (C# Removed the remark about C#8 nullable types because it does not apply to bool.)
Line 708:
 
=={{header|C sharp|C#}}==
In C#, there are the reserved keywords <code>true</code> and <code>false</code>. Variables to hold these values are declared as either <code>bool</code> or <code>Boolean</code>. These types are identical, as <code>bool</code> is just shortandshorthand for <code>Boolean</code>. The collection type <code>BitArray</code> returns its values as <code>Boolean</code>, packing 8 values into each byte (In contrast, the <code>Boolean</code> type uses the entire byte for one value).
 
InThere C#is 8.0also nullablethe <code>Nullable<T></code> type wasthat introducedrepresents andall whenvalues appliedof toits underlying value type <code>boolT</code> supports all values and an additional <code>null</code> value. andIt usefulhas fora someshorthand applicationsnotation: where<code>T?</code> the(When value<code>T</code> canis bea undefinedreference ortype, <code>T?</code> means something else. It is not a different type, but just a hint to the missingcompiler.)
So, when applied to <code>bool</code>, we have a <code>bool?</code> type that supports 3 values: <code>true</code>, <code>false</code> and <code>null</code>. This can be useful for some applications where the value can be undefined or missing.
 
<lang csharp>bool? value = null</lang>
196

edits