2014-11-02 47 views
0

考虑这种情况:C#LINQ追加多个项目,而不是返回其数组

struct Account 
{ 
    public List<string> CharacterNames; 
} 
List<Account> accounts = new List<Account>(); 
// add items to accounts here 

accounts.Select(a=>a.CharacterNames); // I want it to select string, not string[]. 

所以,它给我的角色名字列表。但我想要的是所有人物的名字。

有没有LINQ解决方案来解决这个问题?

回答

4

您可以使用SelectMany扁平化的结果:

accounts.SelectMany(a => a.CharacterNames); 
+0

感觉清楚!但是,通过谷歌搜索这类问题非常困难。 – Laie 2014-11-03 00:20:38