以下两种方法:(备忘)
1. if
(obj != null)
2. string objName = (obj ?? string.Empty).ToString();
??运算符,又称为null-coalescing operator,如果左侧操作数为null,则返回右侧操作数的值, 如果不为null则返回左侧操作数的值。它既可以应用于可空类型,有可以应用于引用类型。

来自:
http://www.cnblogs.com/anytao/archive/2008/07/31/must_net_21.html
[你必须知道的.NET]第二十一回:认识全面的null

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
  • 2022-12-23
  • 2022-02-24
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案