Rex*_*x M 20

避免意外的错误myVar = null(哎呀)是一种习惯.它在某些语言中仍然有用,但C#会保护你不要这样做,因此没有必要.


And*_*are 8

这是来自C的保留,旧的编译器不会抓住这个:

if (foo = null)
Run Code Online (Sandbox Code Playgroud)

当你的意思是这样的:

if (foo == null)
Run Code Online (Sandbox Code Playgroud)

经典的笑话例子是这个错误:

if (fireTheNukes = true)
    fireTheNukes();
Run Code Online (Sandbox Code Playgroud)

这通常被认为是一种古老的模式,因为任何有价值的编译器都会在条件语句中捕获赋值.我会在你的代码中避免这种模式,因为它现在没有任何用处.