相关疑难解决方法(0)

在ToString()之前检查null

这是场景......

if (entry.Properties["something"].Value != null)
  attribs.something = entry.Properties["something"].Value.ToString();
Run Code Online (Sandbox Code Playgroud)

虽然有效且正常工作,但这看起来很难看.如果我在执行ToString()之前没有检查null,那么如果属性为null,则抛出异常.有没有更好的方法来处理这种情况?

非常感激!

.net c# string properties

75
推荐指数
3
解决办法
8万
查看次数

标签 统计

.net ×1

c# ×1

properties ×1

string ×1