考虑以下代码:
class Program
{
static void Main(string[] args)
{
string s = null;
bool b = s is string;
Console.WriteLine(b);
}
}
在上面的代码中,s是字符串
,但b是false
。
实际上s是字符串,为什么我会得到这个结果?
编译器为什么会有这种行为?
s
不是一个字符串,它是一个空引用。如果它引用了某些东西,那个东西就会是一个字符串。 - Roger Rowland