views:

76

answers:

4

I've picked up some code from a colleague, and in one of his methods he has a boolean parameter: ByVal showProactiveChases As Boolean?. I had to look up the ? operator yesterday to see that it denotes a Nullable type. My question is, if I change it to: ByVal showProactiveChases As Nullable(Of Boolean), does the meaning remain the same? I think provided it doesn't change the meaning the second way is much more readable.

+3  A: 

Yes, the meaning is exactly the same.

Boolean? and Nullable(Of Boolean) will be compiled to exactly the same IL.

(I personally find the first version more readable, but it's all down to personal taste.)

LukeH
A: 

Yes, it is the same.

? is the shorthand for Nullable<T>

Frederik Gheysels
A: 

Yes, the ? operator is in fact a shortcut for Nullable or Nullable(Of T).

Gerrie Schenck
+2  A: 

There's a third option too:

The following example constructs a nullable Boolean type and declares a variable of that type. You can write the declaration in three ways:

Dim ridesBusToWork1? As Boolean
Dim ridesBusToWork2 As Boolean?
Dim ridesBusToWork3 As Nullable(Of Boolean)
AakashM