Why does >= return false when == returns true for null values?

There was a huge debate about this oddity when the feature was originally designed back in C# 2.0. The problem is that C# users are completely used to this being meaningful: if(someReference == null) When extending equality to nullable value types, you have the following choices. Nullable equality is truly lifted. If one or both … Read more

.NET – Convert Generic Collection to DataTable

Then presumably you’ll need to lift them to the non-nullable form, using Nullable.GetUnderlyingType, and perhaps change a few null values to DbNull.Value… Change the assignment to be: row[prop.Name] = prop.GetValue(item) ?? DBNull.Value; and when adding the columns to be: table.Columns.Add(prop.Name, Nullable.GetUnderlyingType( prop.PropertyType) ?? prop.PropertyType); And it works. (?? is the null-coalescing operator; it uses the … Read more

How to check multiple objects for nullity?

In Java 8, you could use Stream.allMatch to check whether all of the values match a certain condition, such as being null. Not much shorter, but maybe a bit easier to read. if (Stream.of(a, b, c).allMatch(x -> x == null)) { … } And analogeously for anyMatch and noneMatch. About your “more challenging example”: In … Read more

Why can’t I check if a ‘DateTime’ is ‘Nothing’?

This is one of the biggest sources of confusion with VB.Net, IMO. Nothing in VB.Net is the equivalent of default(T) in C#: the default value for the given type. For value types, this is essentially the equivalent of ‘zero’: 0 for Integer, False for Boolean, DateTime.MinValue for DateTime, … For reference types, it is the … Read more

Do short-circuiting operators || and && exist for nullable booleans? The RuntimeBinder sometimes thinks so

First of all, thanks for pointing out that the spec isn’t clear on the non-dynamic nullable-bool case. I will fix that in a future version. The compiler’s behavior is the intended behavior; && and || are not supposed to work on nullable bools. The dynamic binder does not seem to implement this restriction, though. Instead, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)