我想获得同一个人参加过的其他数量的游戏。例如,lisa 参加了第 7 场比赛,这是另一场比赛。Tim 和 Josh 都参加了第 2 场比赛,但也参加了其他 3 场比赛。有没有办法通过 Igrouping 比较组并查看值是否相同?
public List<Game> DummyDataSet()
{
dataSet.Add(new Game { GameNo = 1, FirstName = "Lisa" });
dataSet.Add(new Game { GameNo= 2, FirstName = "Tim" });
dataSet.Add(new Game { GameNo = 2, FirstName = "Josh" });
dataSet.Add(new Game { GameNo = 3, FirstName = "Susan" });
dataSet.Add(new Gamee { GameNo = 4, FirstName = "Tim" });
dataSet.Add(new Gamee { GameNo = 5, FirstName = "Tim" });
dataSet.Add(new Gamee { GameNo = 5, FirstName = "Josh" });
dataSet.Add(new Game { GameNo = 6, FirstName = "Josh" });
dataSet.Add(new Game { GameNo = 7, FirstName = "Lisa" });
return dataSet;
}
public void numOfOtherMissions()
{
List<Game> something;
something = DummyDataSet();
var grouped = something.ToLookup(x => x.GameNo, x => x.FirstName);
foreach (IGrouping<int, string> item in grouped)
{
Console.Write(item.Key);
Console.Write(": ");
var result = grouped.ToLookup(z => FirstName);
foreach (var value in item)
{
int games = 0;
if(result == item)
{
othergames++;
}
else
{
othergames = 0;
}
Console.Write(value + " " + othergames);
Console.WriteLine();
}
}
}