Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.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# 如何从列表中打印不同的名称?_C#_Linq_Linqpad - Fatal编程技术网

C# 如何从列表中打印不同的名称?

C# 如何从列表中打印不同的名称?,c#,linq,linqpad,C#,Linq,Linqpad,以下是我的玩家列表以及他们喜欢的游戏: 播放者1:哇,RS,MS 玩家2:AQ、CoD、LoL、RS 玩家3:D3,马里奥,哇 播放者4:哈哈,小姐 列表属性是公共列表游戏{get;set;} 这就是我在代码中尝试过的 var result = Gamer.GetGamer() .Select(x => x.Games) .Distinct() .Dump("List of Diff

以下是我的玩家列表以及他们喜欢的游戏:

播放者1:哇,RS,MS

玩家2:AQ、CoD、LoL、RS

玩家3:D3,马里奥,哇

播放者4:哈哈,小姐

列表属性是
公共列表游戏{get;set;}

这就是我在代码中尝试过的

var result = Gamer.GetGamer()
                  .Select(x => x.Games)
                  .Distinct()
                  .Dump("List of Different Games Played");
GetGamer()
方法返回玩家列表

现在的问题是,它将显示游戏列表,但会重复,而不是有不同的值


我真正想要的是正在玩的不同游戏的总数。如何在不重复的情况下显示它们?

使用
SelectMany
而不是
Select

Gamer.GetGamer()
     .SelectMany(x => x.Games)
     .Distinct()
     .Dump();
如果您想获得
Count
只需在
Distinct
之后添加
Count