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


C# System.Collections.Generic.Min方法代码示例

本文整理汇总了C#中System.Collections.Generic.Min方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.Min方法的具体用法?C# System.Collections.Generic.Min怎么用?C# System.Collections.Generic.Min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Generic的用法示例。


在下文中一共展示了System.Collections.Generic.Min方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MinInt32

 public void MinInt32()
 {
     var one = Enumerable.Range(1, 10).ToArray();
     var minusTen = new[] { -1, -10, 10, 200, 1000 };
     var hundred = new[] { 3000, 100, 200, 1000 };
     Assert.Equal(1, one.Min());
     Assert.Equal(-10, minusTen.Min());
     Assert.Equal(100, hundred.Min());
     Assert.Equal(int.MinValue, one.Concat(Enumerable.Repeat(int.MinValue, 1)).Min());
 }
开发者ID:kyulee1,项目名称:corefx,代码行数:10,代码来源:MinTests.cs

示例2: MinInt64

 public void MinInt64()
 {
     var one = Enumerable.Range(1, 10).Select(i => (long)i).ToArray();
     var minusTen = new[] { -1L, -10, 10, 200, 1000 };
     var hundred = new[] { 3000L, 100, 200, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42L, 1).Min());
     Assert.Equal(1, one.Min());
     Assert.Equal(-10, minusTen.Min());
     Assert.Equal(100, hundred.Min());
     Assert.Equal(long.MinValue, one.Concat(Enumerable.Repeat(long.MinValue, 1)).Min());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<long>().Min());
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:MinMaxTests.cs

示例3: MinSingle

 public void MinSingle()
 {
     var one = Enumerable.Range(1, 10).Select(i => (float)i).ToArray();
     var minusTen = new[] { -1F, -10, 10, 200, 1000 };
     var hundred = new[] { 3000F, 100, 200, 1000 };
     Assert.Equal(42F, Enumerable.Repeat(42F, 1).Min());
     Assert.Equal(1L, one.Min());
     Assert.Equal(-10L, minusTen.Min());
     Assert.Equal(100L, hundred.Min());
     Assert.Equal(float.MinValue, one.Concat(Enumerable.Repeat(float.MinValue, 1)).Min());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<float>().Min());
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:MinMaxTests.cs

示例4: MinInt32

 public void MinInt32()
 {
     var one = Enumerable.Range(1, 10).ToArray();
     var minusTen = new[] { -1, -10, 10, 200, 1000 };
     var hundred = new[] { 3000, 100, 200, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42, 1).Min());
     Assert.Equal(1, one.Min());
     Assert.Equal(-10, minusTen.Min());
     Assert.Equal(100, hundred.Min());
     Assert.Equal(int.MinValue, one.Concat(Enumerable.Repeat(int.MinValue, 1)).Min());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<int>().Min());
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:MinMaxTests.cs

示例5: MinString

 public void MinString()
 {
     var one = Enumerable.Range(1, 10).Select(i => i.ToString()).ToArray();
     var agents = new[] { "Alice", "Bob", "Charlie", "Eve", "Mallory", "Trent", "Victor"};
     var confusedAgents = new[] { null, "Charlie", null, "Victor", "Trent", null, "Eve", "Alice", "Mallory", "Bob" };
     Assert.Equal("1", one.Min());
     Assert.Equal("Alice", agents.Min());
     Assert.Equal("Alice", confusedAgents.Min());
 }
开发者ID:kyulee1,项目名称:corefx,代码行数:9,代码来源:MinTests.cs

示例6: NaNFirstDouble

 public void NaNFirstDouble()
 {
     var nanThenOne = Enumerable.Range(1, 10).Select(i => (double)i).Concat(Enumerable.Repeat(double.NaN, 1)).ToArray();
     var nanThenMinusTen = new[] { -1F, -10, double.NaN, 10, 200, 1000 };
     var nanThenMinValue = new[] { double.MinValue, 3000F, 100, 200, double.NaN, 1000 };
     Assert.True(double.IsNaN(nanThenOne.Min()));
     Assert.True(double.IsNaN(nanThenMinusTen.Min()));
     Assert.True(double.IsNaN(nanThenMinValue.Min()));
     var nanWithNull = new[] { default(double?), double.NaN, default(double?) };
     Assert.True(double.IsNaN(nanWithNull.Min().Value));
 }
开发者ID:kyulee1,项目名称:corefx,代码行数:11,代码来源:MinTests.cs

示例7: MinDateTime

 public void MinDateTime()
 {
     var one = Enumerable.Range(1, 10).Select(i => new DateTime(2000, 1, i)).ToArray();
     var newYears = new[]
     {
         new DateTime(2000, 12, 1),
         new DateTime(2000, 1, 1),
         new DateTime(2000, 1, 12)
     };
     var hundred = new[]
     {
         new DateTime(3000, 1, 1),
         new DateTime(100, 1, 1),
         new DateTime(200, 1, 1),
         new DateTime(1000, 1, 1)
     };
     Assert.Equal(DateTime.MinValue, one.Concat(Enumerable.Repeat(DateTime.MinValue, 1)).Min());
     Assert.Equal(new DateTime(2000, 1, 1), one.Min());
     Assert.Equal(new DateTime(2000, 1, 1), newYears.Min());
     Assert.Equal(new DateTime(100, 1, 1), hundred.Min());
 }
开发者ID:kyulee1,项目名称:corefx,代码行数:21,代码来源:MinTests.cs

示例8: MinDouble

 public void MinDouble()
 {
     var one = Enumerable.Range(1, 10).Select(i => (double)i).ToArray();
     var minusTen = new[] { -1D, -10, 10, 200, 1000 };
     var hundred = new[] { 3000D, 100, 200, 1000 };
     Assert.Equal(42D, Enumerable.Repeat(42D, 1).Min());
     Assert.Equal(1D, one.Min());
     Assert.Equal(-10D, minusTen.Min());
     Assert.Equal(100D, hundred.Min());
     Assert.Equal(double.MinValue, one.Concat(Enumerable.Repeat(double.MinValue, 1)).Min());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<double>().Min());
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:MinMaxTests.cs

示例9: MinNullableDecimal

 public void MinNullableDecimal()
 {
     var one = Enumerable.Range(1, 10).Select(i => (decimal?)i).ToArray();
     var minusTen = new[] { default(decimal?), -1M, -10, 10, 200, 1000 };
     var hundred = new[] { default(decimal?), 3000M, 100, 200, 1000 };
     Assert.Equal(1M, one.Min());
     Assert.Equal(-10M, minusTen.Min());
     Assert.Equal(100M, hundred.Min());
     Assert.Equal(decimal.MinValue, one.Concat(Enumerable.Repeat((decimal?)decimal.MinValue, 1)).Min());
 }
开发者ID:kyulee1,项目名称:corefx,代码行数:10,代码来源:MinTests.cs

示例10: Min_Int_WithSelectorAccessingProperty

 public void Min_Int_WithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=10 },
         new { name="John", num=-105 },
         new { name="Bob", num=-30 }
     };
     Assert.Equal(-105, source.Min(e => e.num));
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:10,代码来源:MinTests.cs

示例11: Min_Double_WithSelectorAccessingProperty

 public void Min_Double_WithSelectorAccessingProperty()
 {
     var source = new[]
     {
         new { name="Tim", num=-45.5 },
         new { name="John", num=-132.5 },
         new { name="Bob", num=20.45 }
     };
     Assert.Equal(-132.5, source.Min(e => e.num));
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:10,代码来源:MinTests.cs

示例12: NaNFirstSingleWithSelector

 public void NaNFirstSingleWithSelector()
 {
     var nanThenOne = Enumerable.Range(1, 10).Select(i => (float)i).Concat(Enumerable.Repeat(float.NaN, 1)).ToArray();
     var nanThenMinusTen = new[] { -1F, -10, float.NaN, 10, 200, 1000 };
     var nanThenMinValue = new[] { float.MinValue, 3000F, 100, 200, float.NaN, 1000 };
     Assert.True(float.IsNaN(nanThenOne.Min(x => x)));
     Assert.True(float.IsNaN(nanThenMinusTen.Min(x => x)));
     Assert.True(float.IsNaN(nanThenMinValue.Min(x => x)));
     var nanWithNull = new[] { default(float?), float.NaN, default(float?) };
     Assert.True(float.IsNaN(nanWithNull.Min(x => x).Value));
 }
开发者ID:kyulee1,项目名称:corefx,代码行数:11,代码来源:MinTests.cs

示例13: MinDouble

 public void MinDouble()
 {
     var one = Enumerable.Range(1, 10).Select(i => (double)i).ToArray();
     var minusTen = new[] { -1D, -10, 10, 200, 1000 };
     var hundred = new[] { 3000D, 100, 200, 1000 };
     Assert.Equal(1D, one.Min());
     Assert.Equal(-10D, minusTen.Min());
     Assert.Equal(100D, hundred.Min());
     Assert.Equal(double.MinValue, one.Concat(Enumerable.Repeat(double.MinValue, 1)).Min());
 }
开发者ID:kyulee1,项目名称:corefx,代码行数:10,代码来源:MinTests.cs

示例14: MinNullableSingleWithSelectorAccessingProperty

        public void MinNullableSingleWithSelectorAccessingProperty()
        {
            var source = new[]{
                new {name="Tim", num=(float?)-45.5f},
                new {name="John", num=(float?)-132.5f},
                new {name="Bob", num=default(float?)}
            };

            Assert.Equal(-132.5f, source.Min(e => e.num));
        }
开发者ID:kyulee1,项目名称:corefx,代码行数:10,代码来源:MinTests.cs

示例15: MinNullableDoubleWithSelector

 public void MinNullableDoubleWithSelector()
 {
     var one = Enumerable.Range(1, 10).Select(i => (double?)i).ToArray();
     var minusTen = new[] { default(double?), -1D, -10, 10, 200, 1000 };
     var hundred = new[] { default(double?), 3000D, 100, 200, 1000 };
     Assert.Equal(42D, Enumerable.Repeat((double?)42, 1).Min(x => x));
     Assert.Equal(1D, one.Min(x => x));
     Assert.Equal(-10D, minusTen.Min(x => x));
     Assert.Equal(100D, hundred.Min(x => x));
     Assert.Equal(double.MinValue, one.Concat(Enumerable.Repeat((double?)double.MinValue, 1)).Min(x => x));
     Assert.Null(Enumerable.Empty<double?>().Min(x => x));
     Assert.Null(Enumerable.Repeat(default(double?), 100).Min(x => x));
 }
开发者ID:kyulee1,项目名称:corefx,代码行数:13,代码来源:MinTests.cs


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