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


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

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


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

示例1: MaxInt32

 public void MaxInt32()
 {
     var ten = Enumerable.Range(1, 10).ToArray();
     var minusTen = new[] { -100, -15, -50, -10 };
     var thousand = new[] { -16, 0, 50, 100, 1000 };
     Assert.Equal(10, ten.Max());
     Assert.Equal(-10, minusTen.Max());
     Assert.Equal(1000, thousand.Max());
     Assert.Equal(int.MaxValue, thousand.Concat(Enumerable.Repeat(int.MaxValue, 1)).Max());
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:10,代码来源:MaxTests.cs

示例2: MaxInt64

 public void MaxInt64()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (long)i).ToArray();
     var minusTen = new[] { -100L, -15, -50, -10 };
     var thousand = new[] { -16L, 0, 50, 100, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42L, 1).Max());
     Assert.Equal(10, ten.Max());
     Assert.Equal(-10, minusTen.Max());
     Assert.Equal(1000, thousand.Max());
     Assert.Equal(long.MaxValue, thousand.Concat(Enumerable.Repeat(long.MaxValue, 1)).Max());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<long>().Max());
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:MinMaxTests.cs

示例3: MaxInt32

 public void MaxInt32()
 {
     var ten = Enumerable.Range(1, 10).ToArray();
     var minusTen = new[] { -100, -15, -50, -10 };
     var thousand = new[] { -16, 0, 50, 100, 1000 };
     Assert.Equal(42, Enumerable.Repeat(42, 1).Max());
     Assert.Equal(10, ten.Max());
     Assert.Equal(-10, minusTen.Max());
     Assert.Equal(1000, thousand.Max());
     Assert.Equal(int.MaxValue, thousand.Concat(Enumerable.Repeat(int.MaxValue, 1)).Max());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<int>().Max());
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:MinMaxTests.cs

示例4: MaxSingle

 public void MaxSingle()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (float)i).ToArray();
     var minusTen = new[] { -100F, -15, -50, -10 };
     var thousand = new[] { -16F, 0, 50, 100, 1000 };
     Assert.Equal(42F, Enumerable.Repeat(42F, 1).Max());
     Assert.Equal(10F, ten.Max());
     Assert.Equal(-10F, minusTen.Max());
     Assert.Equal(1000F, thousand.Max());
     Assert.Equal(float.MaxValue, thousand.Concat(Enumerable.Repeat(float.MaxValue, 1)).Max());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<float>().Max());
 }
开发者ID:rcabr,项目名称:corefx,代码行数:12,代码来源:MinMaxTests.cs

示例5: MaxDecimal

 public void MaxDecimal()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (decimal)i).ToArray();
     var minusTen = new[] { -100M, -15, -50, -10 };
     var thousand = new[] { -16M, 0, 50, 100, 1000 };
     Assert.Equal(42M, Enumerable.Repeat(42M, 1).Max());
     Assert.Equal(10M, ten.Max());
     Assert.Equal(-10M, minusTen.Max());
     Assert.Equal(1000M, thousand.Max());
     Assert.Equal(decimal.MaxValue, thousand.Concat(Enumerable.Repeat(decimal.MaxValue, 1)).Max());
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<decimal>().Max());
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:MinMaxTests.cs

示例6: MaxInt64WithSelectorAccessingProperty

 public void MaxInt64WithSelectorAccessingProperty()
 {
     var source = new[]{
         new { name="Tim", num=10L },
         new { name="John", num=-105L },
         new { name="Bob", num=long.MaxValue }
     };
     Assert.Equal(long.MaxValue, source.Max(e => e.num));
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:9,代码来源:MaxTests.cs

示例7: MaxInt32WithSelectorAccessingProperty

        public void MaxInt32WithSelectorAccessingProperty()
        {
            var source = new[]{
                new { name="Tim", num=10 },
                new { name="John", num=-105 },
                new { name="Bob", num=30 }
            };

            Assert.Equal(30, source.Max(e => e.num));
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:10,代码来源:MaxTests.cs

示例8: MaxDateTime

 public void MaxDateTime()
 {
     var ten = Enumerable.Range(1, 10).Select(i => new DateTime(2000, 1, i)).ToArray();
     var newYearsEve = new[]
     {
         new DateTime(2000, 12, 1),
         new DateTime(2000, 12, 31),
         new DateTime(2000, 1, 12)
     };
     var threeThousand = new[]
     {
         new DateTime(3000, 1, 1),
         new DateTime(100, 1, 1),
         new DateTime(200, 1, 1),
         new DateTime(1000, 1, 1)
     };
     Assert.Equal(new DateTime(2000, 1, 10), ten.Max());
     Assert.Equal(new DateTime(2000, 12, 31), newYearsEve.Max());
     Assert.Equal(new DateTime(3000, 1, 1), threeThousand.Max());
     Assert.Equal(DateTime.MaxValue, threeThousand.Concat(Enumerable.Repeat(DateTime.MaxValue, 1)).Max());
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:21,代码来源:MaxTests.cs

示例9: MaxNullableDecimal

 public void MaxNullableDecimal()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (decimal?)i).ToArray();
     var minusTen = new[] { default(decimal?), -100M, -15, -50, -10 };
     var thousand = new[] { default(decimal?), -16M, 0, 50, 100, 1000 };
     Assert.Equal(42M, Enumerable.Repeat((decimal?)42, 1).Max());
     Assert.Equal(10M, ten.Max());
     Assert.Equal(-10M, minusTen.Max());
     Assert.Equal(1000M, thousand.Max());
     Assert.Equal(decimal.MaxValue, thousand.Concat(Enumerable.Repeat((decimal?)decimal.MaxValue, 1)).Max());
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:11,代码来源:MaxTests.cs

示例10: MaxNullableSingle

 public void MaxNullableSingle()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (float?)i).ToArray();
     var minusTen = new[] { default(float?), -100F, -15, -50, -10 };
     var thousand = new[] { default(float?), -16F, 0, 50, 100, 1000 };
     Assert.Equal(10F, ten.Max());
     Assert.Equal(-10F, minusTen.Max());
     Assert.Equal(1000F, thousand.Max());
     Assert.Equal(float.MaxValue, thousand.Concat(Enumerable.Repeat((float?)float.MaxValue, 1)).Max());
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:10,代码来源:MaxTests.cs

示例11: MaxDoubleWithSelectorAccessingField

 public void MaxDoubleWithSelectorAccessingField()
 {
     var source = new[]{
         new { name="Tim", num=40.5 },
         new { name="John", num=-10.25 },
         new { name="Bob", num=100.45 }
     };
     Assert.Equal(100.45, source.Max(e => e.num));
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:9,代码来源:MaxTests.cs

示例12: MaxDoubleWithSelector

 public void MaxDoubleWithSelector()
 {
     var ten = Enumerable.Range(1, 10).Select(i => (double)i).ToArray();
     var minusTen = new[] { -100D, -15, -50, -10 };
     var thousand = new[] { -16D, 0, 50, 100, 1000 };
     Assert.Equal(42D, Enumerable.Repeat(42D, 1).Max(x => x));
     Assert.Equal(10D, ten.Max(x => x));
     Assert.Equal(-10D, minusTen.Max(x => x));
     Assert.Equal(1000D, thousand.Max(x => x));
     Assert.Equal(double.MaxValue, thousand.Concat(Enumerable.Repeat(double.MaxValue, 1)).Max(x => x));
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:11,代码来源:MaxTests.cs

示例13: should_get_maximum_element_using_max

        public void should_get_maximum_element_using_max()
        {
            var sequence = new[] { 1, 2, 3, 4, 5 };

            int maxNumber = sequence.Max();

            // please update variable value to fix the test.
            const int expectedMaxNumber = 0;

            Assert.Equal(expectedMaxNumber, maxNumber);
        }
开发者ID:chenbojian,项目名称:01_NewbieVillage,代码行数:11,代码来源:24_LinqBasics.cs

示例14: MaxDateTimeWithSelector

 public void MaxDateTimeWithSelector()
 {
     var ten = Enumerable.Range(1, 10).Select(i => new DateTime(2000, 1, i)).ToArray();
     var newYearsEve = new[]
     {
         new DateTime(2000, 12, 1),
         new DateTime(2000, 12, 31),
         new DateTime(2000, 1, 12)
     };
     var threeThousand = new[]
     {
         new DateTime(3000, 1, 1),
         new DateTime(100, 1, 1),
         new DateTime(200, 1, 1),
         new DateTime(1000, 1, 1)
     };
     Assert.Equal(new DateTime(2000, 1, 10), ten.Max(x => x));
     Assert.Equal(new DateTime(2000, 12, 31), newYearsEve.Max(x => x));
     Assert.Equal(new DateTime(3000, 1, 1), threeThousand.Max(x => x));
     Assert.Equal(DateTime.MaxValue, threeThousand.Concat(Enumerable.Repeat(DateTime.MaxValue, 1)).Max(x => x));
     Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<DateTime>().Max(x => x));
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:22,代码来源:MinMaxTests.cs

示例15: 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.False(float.IsNaN(nanThenOne.Max(x => x)));
     Assert.False(float.IsNaN(nanThenMinusTen.Max(x => x)));
     Assert.False(float.IsNaN(nanThenMinValue.Max(x => x)));
     var nanWithNull = new[] { default(float?), float.NaN, default(float?) };
     Assert.True(float.IsNaN(nanWithNull.Max(x => x).Value));
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:11,代码来源:MaxTests.cs


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