开发者

Marking Parameters as Nullable

I've picked up some code from a colleague, and in开发者_如何学JAVA 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.


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.)


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)


Yes, it is the same.

? is the shorthand for Nullable<T>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜