Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#LINQ追加多个项,而不是返回其数组_C#_Linq - Fatal编程技术网

C#LINQ追加多个项,而不是返回其数组

C#LINQ追加多个项,而不是返回其数组,c#,linq,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[]. s

考虑这种情况:

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[].
struct帐户
{
公共列表字符名称;
}
列表帐户=新列表();
//在此处向帐户添加项目
accounts.Select(a=>a.CharacterNames);//我希望它选择字符串,而不是字符串[]。
所以它给了我角色名列表。但我想要的是所有角色的名字


有解决此问题的LINQ解决方案吗?

您可以使用
SelectMany
将结果展平:

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

您可以使用
SelectMany
将结果展平:

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

清楚点!然而,通过谷歌搜索这种问题是非常困难的。感觉清楚!然而,通过谷歌搜索这类问题是非常困难的。