This is pretty interesting. In the above example, it is pretty clear that something strange is happening. However, Qaru is actually not a good place to "report" errors. If you think you really found a bug, you can post your results to Microsoft connect .
I did a connection search, and there are a few quirks with both VB.NET and the C # triple operator, especially when Nullable types are involved. Could this be just one of them?
For what it's worth, you can even simplify things to look like this:
Dim pDate As Date? pDate = If(False, "", Nothing) ' Works fine pDate = If(False, String.Empty, Nothing) ' Doesn't work
It is worth noting that every situation that seems violated (all cases expect the use of "" ) works when the line looks like this: pDate = If(False, String.Empty, CType(Nothing, Date?))
In addition, Option Strict [On|Off] plays a very large role in this. When Option Strict On installed, then all these are compilation errors. This behavior can only be seen with Option Strict Off . I have compiled an example of all situations here .
In the end, I don't think this is really a mistake, but just one of the pitfalls of using Option Strict Off . It seems strange (illogical), but again it matters Option Strict Off .;)
source share