本文整理汇总了C#中System.Linq.Distinct方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.Distinct方法的具体用法?C# System.Linq.Distinct怎么用?C# System.Linq.Distinct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.Distinct方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Distinct_removes_duplicates_using_provided_equality_function
public void Distinct_removes_duplicates_using_provided_equality_function()
{
var values = new[] { "a", "b", "A" };
Assert.True(
new[] { "a", "b" }.SequenceEqual(
values.Distinct((a, b) => a.Equals(b, StringComparison.OrdinalIgnoreCase))));
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:8,代码来源:DynamicEqualityComparerLinqIntegrationTests.cs
示例2: DistinctTest
public void DistinctTest()
{
// ARRANGE
var list = new[] { "a", "aa", "aaa", "b", "bb", "bbb" };
// ACT
var distinct = list.Distinct(x => x.Length).ToList();
// ASSERT
CollectionAssert.AreEqual(new[] { "a", "aa", "aaa" }, distinct);
}
示例3: ShouldFilterOutDuplicateGcSettings
public void ShouldFilterOutDuplicateGcSettings()
{
var gcSettings = new[]
{
new GcBenchmarkSetting(GcMetric.TotalCollections, GcGeneration.Gen0, AssertionType.Throughput,
Assertion.Empty),
new GcBenchmarkSetting(GcMetric.TotalCollections, GcGeneration.Gen0, AssertionType.Total,
Assertion.Empty),
new GcBenchmarkSetting(GcMetric.TotalCollections, GcGeneration.Gen1, AssertionType.Throughput,
Assertion.Empty),
new GcBenchmarkSetting(GcMetric.TotalCollections, GcGeneration.Gen1, AssertionType.Total,
Assertion.Empty)
};
var distinctGcSettings = gcSettings.Distinct(GcBenchmarkSetting.GcBenchmarkDistinctComparer.Instance);
// according to normal equality, all 4 should be distinct as they have different assertion settings
Assert.Equal(4, gcSettings.Distinct().Count());
// but using our special EqualityComparer<T>, they really track only 2 distinct metrics
Assert.Equal(2, distinctGcSettings.Count());
}
示例4: ShouldFilterOutDuplicateMemorySettings
public void ShouldFilterOutDuplicateMemorySettings()
{
var memorySettings = new[]
{
new MemoryBenchmarkSetting(MemoryMetric.TotalBytesAllocated,
Assertion.Empty),
new MemoryBenchmarkSetting(MemoryMetric.TotalBytesAllocated,
new Assertion(MustBe.ExactlyEqualTo, 1.0d, null)),
};
var distinctMemorySettings = memorySettings.Distinct(MemoryBenchmarkSetting.MemoryBenchmarkDistinctComparer.Instance);
Assert.Equal(2, memorySettings.Length);
Assert.Equal(1, distinctMemorySettings.Count());
}
示例5: ShouldFilterOutDuplicateCounterSettings
public void ShouldFilterOutDuplicateCounterSettings()
{
var counterSettings = new[]
{
new CounterBenchmarkSetting("counter1", AssertionType.Throughput, Assertion.Empty),
new CounterBenchmarkSetting("counter1", AssertionType.Total, Assertion.Empty),
new CounterBenchmarkSetting("counter2", AssertionType.Throughput, Assertion.Empty),
new CounterBenchmarkSetting("counter2", AssertionType.Total, Assertion.Empty),
};
var distinctMemorySettings = counterSettings.Distinct(CounterBenchmarkSetting.CounterBenchmarkDistinctComparer.Instance).ToList();
Assert.Equal(4, counterSettings.Length);
Assert.Equal(2, distinctMemorySettings.Count());
Assert.Equal(1, distinctMemorySettings.Count(x => x.CounterName.CounterName.Equals("counter1")));
Assert.Equal(1, distinctMemorySettings.Count(x => x.CounterName.CounterName.Equals("counter2")));
}
示例6: TestDistinct
public void TestDistinct()
{
var numbers = new[] {1, 2, 3, 3, 1, 1,};
var uniqueNumbers = numbers.Distinct();
Assert.That(uniqueNumbers.Count(), Is.EqualTo(3));
}