var data = (from x in simpMeds.Descendants("PharmacyReviewer")
select x.Element("DisplayName").Value.ToString()).FirstOrDefault();
答案 0 :(得分:0)
var data = (from x in simpMeds.Descendants("PharmacyReviewer")
select x.Element("DisplayName").Value.ToString()).FirstOrDefault()
必须选中null才能获取数据属性。即:
var property = data?.Property1; // property == null if data == null
必须选中null才能选择另一个对象。即:
var myValue = data ?? otherData; // myValue == otherData if data == null
或者简单地
if(data == null)
//do something
else
//do other thing