私はこれに出くわし、C#の場合と同じように、VB.NETで失敗すると予想されるのに、なぜこれが機能するのかを誰かが説明できるかどうか疑問に思っていました.
//The C# Version
struct Person {
public string name;
}
...
Person someone = null; //Nope! Can't do that!!
Person? someoneElse = null; //No problem, just like expected
しかし、VB.NETでは...
Structure Person
Public name As String
End Structure
...
Dim someone As Person = Nothing 'Wha? this is okay?
Nothing は null ( Nothing != null - LOL?)と同じではありませんか、それとも 2 つの言語間で同じ状況を処理する方法が異なるだけですか?
2つの間で処理が異なるのはなぜですか?
[アップデート]
コメントのいくつかを考えると、私はこれをもう少し台無しにしました...VB.NETで何かをnullにすることを許可したい場合は、実際にNullableを使用する必要があるようです...たとえば...
'This is false - It is still a person'
Dim someone As Person = Nothing
Dim isSomeoneNull As Boolean = someone.Equals(Nothing) 'false'
'This is true - the result is actually nullable now'
Dim someoneElse As Nullable(Of Person) = Nothing
Dim isSomeoneElseNull As Boolean = someoneElse.Equals(Nothing) 'true'
奇妙すぎる...