return results.Select(x => new {
VillageName = x.VillageName,
GroupID = x.GroupID,
GroupName = x.GroupName,
CenterID = x.CenterID,
CenterName = x.CenterName,
}).ToList<object>();
答案 0 :(得分:1)
x?.CenterName ?? string.Empty
答案 1 :(得分:-1)
您可以实现C#三元(?:)运算符。 三元运算符的语法为:
Condition ? Expression1 : Expression2;
下面的表达式首先检查空条件,如果条件为空,则将值设置为空。
return results.Select(x => new {
VillageName = x.VillageName,
GroupID = x.GroupID,
GroupName = x.GroupName == null ? "" : x.GroupName,
CenterID = x.CenterID,
CenterName = x.CenterName == null ? "" : x.CenterName,
}).ToList<object>();