選擇我有一個類,就像下面:簡單的Linq查詢到從單個項目
public class ParentData
{
public List<ChildData> ChildDataList { get; set; }
public ChildData AnotherChildData { get; set; }
}
我要尋找一個簡單的Linq查詢,使這些2個成員的選擇。這是我實際上做的:
var query = (from data in parentData.ChildDataList select data)
.Union
(from data in new List<ChildData> { parentData.AnotherChildData } select data);
有沒有更好的方法來做到這一點?謝謝。
可能重複的[有沒有一個neater linq的方式來'聯盟'單個項目?](http://stackoverflow.com/questions/3532176/is-there-a-ne ater-linq-way-to-union-a-single-item) –
確實是重複的。在發佈我之前,我沒有看到這個問題。謝謝! –
如果你不使用相同的措辭,他們可能很難找到,但嘿,這是社區的目的:) 無論如何,現在這兩個問題是相互關聯的,所以任何搜索你的人都會發現鏈接的問題 –