相关疑难解决方法(0)

为什么在VB.NET和C#中检查null值是否存在差异?

VB.NET中会发生这种情况:

Dim x As System.Nullable(Of Decimal) = Nothing
Dim y As System.Nullable(Of Decimal) = Nothing

y = 5
If x <> y Then
    Console.WriteLine("true")
Else
    Console.WriteLine("false") '' <-- I got this. Why?
End If
Run Code Online (Sandbox Code Playgroud)

但在C#中会发生这种情况:

decimal? x = default(decimal?);
decimal? y = default(decimal?);

y = 5;
if (x != y)
{
    Debug.WriteLine("true"); // <-- I got this -- I'm with you, C# :)
}
else
{
    Debug.WriteLine("false");
}
Run Code Online (Sandbox Code Playgroud)

为什么会有区别?

c# vb.net null .net-4.0

108
推荐指数
4
解决办法
5580
查看次数

为什么我不能检查'DateTime'是否'没什么'?

在VB.NET中,有没有办法将DateTime变量设置为"未设置"?为什么它可以设置DateTimeNothing,但没有能够检查它是否是Nothing?例如:

Dim d As DateTime = Nothing
Dim boolNotSet As Boolean = d Is Nothing 
Run Code Online (Sandbox Code Playgroud)

第二个语句抛出此错误:

'Is' operator does not accept operands of type 'Date'. Operands must be reference or
nullable types.
Run Code Online (Sandbox Code Playgroud)

vb.net null datetime nullable nothing

75
推荐指数
3
解决办法
9万
查看次数

如何在VB.net中检索给定结构的默认值?

如果我执行以下语句:

dim defaultDate as Date = Nothing
Run Code Online (Sandbox Code Playgroud)

defaultDate包含Date结构的默认值

我怀疑有一种干净的方式来检索这个值,就像某种buitin常数,但我无法找到它.

问:在VB.net中检索给定结构的默认值的干净方法是什么?

vb.net

4
推荐指数
1
解决办法
714
查看次数

标签 统计

vb.net ×3

null ×2

.net-4.0 ×1

c# ×1

datetime ×1

nothing ×1

nullable ×1