本文整理汇总了C#中System.Linq.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.GroupBy方法的具体用法?C# System.Linq.GroupBy怎么用?C# System.Linq.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.GroupBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GroupBy_Spike
public void GroupBy_Spike() {
var values = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
var groups = values.GroupBy(x => x % 2 == 0);
Assert.That(groups.First().Key, Is.False);
Assert.That(groups.First(), Is.EqualTo(new[] {1, 3, 5, 7, 9}));
Assert.That(groups, Is.EqualTo(new[] { new[] { 1, 3, 5, 7, 9 }, new[] { 2, 4, 6, 8, 10 } }));
}
示例2: When_starting_a_game__everyones_totems_should_be_unique
public void When_starting_a_game__everyones_totems_should_be_unique()
{
var player1Filename = TestHelper.GetSrcFilenameFrom(browser.FindCss("img#player-1"));
var player2Filename = TestHelper.GetSrcFilenameFrom(browser.FindCss("img#player-2"));
var player3Filename = TestHelper.GetSrcFilenameFrom(browser.FindCss("img#player-3"));
var player4Filename = TestHelper.GetSrcFilenameFrom(browser.FindCss("img#player-4"));
var filenames = new[] {player1Filename, player2Filename, player3Filename, player4Filename};
var numberOfUniqueFilenames = filenames.GroupBy(x => x).Count();
Assert.AreEqual(4, numberOfUniqueFilenames, "Expected unique filenames, got: " + string.Join(", ", filenames));
}
示例3: GroupBy_groups_items_using_provided_equality_function
public void GroupBy_groups_items_using_provided_equality_function()
{
var values = new[] { "a", "A" };
Assert.Equal(1, values.GroupBy((a, b) => a.Equals(b, StringComparison.OrdinalIgnoreCase)).Count());
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:6,代码来源:DynamicEqualityComparerLinqIntegrationTests.cs