For instance, looking at the third line of the table, the expression
true & y will only be true if y is true, but the expression true | y will always be
true whatever the value of y is, so the nullable results are null and true, respectively.
When considering the lifted operators and particularly how nullable logic works, the
language designers had two slightly contradictory sets of existing behavior??”C# 1 null
references and SQL NULL values. In many cases these don??™t conflict at all??”C# 1 had no
concept of applying logical operators to null references, so there was no problem in
using the SQL-like results given earlier. The definitions we??™ve seen may surprise some
SQL developers, however, when it comes to comparisons. In standard SQL, the result of
comparing two values (in terms of equality or greater than/less than) is always unknown
if either value is NULL. The result in C# 2 is never null, and in particular two null values
are considered to be equal to each other.
NOTE Reminder: this is C# specific! It??™s worth remembering that the lifted operators
and conversions, along with the bool? logic described in this section,
are all provided by the C# compiler and not by the CLR or the framework
itself. If you use ildasm on code that evaluates any of these nullable operators,
you??™ll find that the compiler has created all the appropriate IL to
test for null values and deal with them accordingly.
Pages:
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270