如何测试通用字典对象以查看它是否为空?我想运行一些代码如下:
while (reportGraphs.MoveNext())
{
reportGraph = (ReportGraph)reportGraphs.Current.Value;
report.ContainsGraphs = true;
break;
}
reportGraph 对象的类型为 System.Collections.Generic.Dictionary 运行此代码时,reportGraphs 字典为空,并且 MoveNext() 立即引发 NullReferenceException。如果有一种更高效的方式来处理空集合,我不想在块周围放置一个 try-catch。
谢谢。