当前位置: 首页>>代码示例>>C#>>正文


C# System.Linq.Distinct方法代码示例

本文整理汇总了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);
        }
开发者ID:vilinski,项目名称:LambdaComparer,代码行数:11,代码来源:EnumerableExTest.cs

示例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());
        }
开发者ID:ThomasBombadil,项目名称:NBench,代码行数:21,代码来源:BenchmarkSettingsSpecs.cs

示例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());
        }
开发者ID:ThomasBombadil,项目名称:NBench,代码行数:14,代码来源:BenchmarkSettingsSpecs.cs

示例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")));
        }
开发者ID:ThomasBombadil,项目名称:NBench,代码行数:16,代码来源:BenchmarkSettingsSpecs.cs

示例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));
 }
开发者ID:kontur-edu,项目名称:intern-2014,代码行数:6,代码来源:07-SortAndDistinct.cs


注:本文中的System.Linq.Distinct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。