6
首选哪个:Nullable <T> .HasValue或Nullable <T>!= null?
我一直使用,Nullable<>.HasValue因为我喜欢语义。但是,最近我正在研究别人现有的代码库,而他们只使用了这些代码库Nullable<> != null。 是否有理由优先使用一个,还是纯粹是偏爱? int? a; if (a.HasValue) // ... 与 int? b; if (b != null) // ...