本文介绍了VB.NET 中的可空类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以在 VB.NET 中使用 Nullable 类型吗?如果是这样,是否有可能有一个 Nullable Integer 可以与 SQL Server 中接受 NULL 的字段一起使用?示例将不胜感激.
Can Nullable Types be used in VB.NET? If so, is it possible to have a Nullable Integer that I can use with a field that accepts NULL in SQL Server? Examples would be appreciated.
推荐答案
您不能在 VB 中将 Null
、Nothing
或 DBNull
分配给一个空的 Integer
,但您可以使用 Nullable(Of Integer)
代替:
You can't assign Null
, Nothing
or DBNull
to a bare Integer
in VB but you can use a Nullable(Of Integer)
instead:
Dim x As Integer? = Nothing
或者,有时(但很少)将整数值装箱在 Object
(可以是 Nothing
)中是有意义的.
Alternatively, it sometimes (but rarely) makes sense to box the integer value in an Object
(which can be Nothing
).
这篇关于VB.NET 中的可空类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!