我目前正在使用
your = from p in (toSelect)
select new
{
last = p.Last,
current = p.CurrentPlayer,
seats = from s in (p.Seated)
select new
{
UID = s.UID,
buyin = s.BuyIn
}
}
p.Seated
是一个数组,每次null
未设置时如何通过s.UID
?我知道“where
”,但我知道哪些座位是免费的(例如null
)
希望这很清楚。
答案 0 :(得分:2)
你可以试试这个:
your = from p in (toSelect)
select new
{
last = p.Last,
current = p.CurrentPlayer,
seats = p.Seated.Select(s => s.UID != null
? new
{
UID = s.UID,
buyin = s.BuyIn
}
: null;
}
答案 1 :(得分:0)
将您分配给seats
的表达式替换为:
seats = p.Seated.Select(s => s != null ? new { UID = s.UID, buyin = s.BuyIn } : null)
希望这很清楚。
我说实话。它不够清楚。 s.UID
是否为可空类型,我们需要与null
进行比较?