重複の可能性:
C# は値の型を null と比較しても問題ありません
C# が許可する理由:
class MyClass
{
public int MyInt;
}
static void Main(string[] args)
{
MyClass m = new MyClass();
if (m.MyInt == null) // <------------- ?
Console.Write("......");
}
Resharper は、「式は常に false です」と言います - これは明らかに - isであり not であるためtrue ですMyInt
int
int?
しかし、C# でこれをコンパイルするにはどうすればよいでしょうか。プロパティは常にそこにあり、そのタイプはint
!