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


C# Queryable.Min方法代码示例

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


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

示例1: MinEx2

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void MinEx2()
{
    Pet[] pets = { new Pet { Name="Barley", Age=8 },
                   new Pet { Name="Boots", Age=4 },
                   new Pet { Name="Whiskers", Age=1 } };

    // Get the Pet object that has the smallest Age value.
    int min = pets.AsQueryable().Min(pet => pet.Age);

    Console.WriteLine("The youngest animal is age {0}.", min);
}
开发者ID:.NET开发者,项目名称:System.Linq,代码行数:17,代码来源:Queryable.Min

输出:

The youngest animal is age 1.

示例2:

double[] doubles = { 1.5E+104, 9E+103, -2E+103 };

double min = doubles.AsQueryable().Min();

Console.WriteLine("The smallest number is {0}.", min);
开发者ID:.NET开发者,项目名称:System.Linq,代码行数:5,代码来源:Queryable.Min

输出:

The smallest number is -2E+103.

示例3: Queryable.Min()

//引入命名空间
using System;
using System.Collections.Generic;
using System.Linq;
public class MainClass {
    public static void Main() {
        int[] numbers = { 10, 9, 8, 7, 6 };
        int count = numbers.Count();          
        int min = numbers.Min();              

    }
}
开发者ID:C#程序员,项目名称:System.Linq,代码行数:12,代码来源:Queryable.Min

示例4: Queryable.Min(filter)

//引入命名空间
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class Employee {
    public int birthYear;
    public string firstName;
    public string lastName;

    public static Employee[] GetEmployees() {
        Employee[] actors = new Employee[] {
        new Employee { birthYear = 1964, firstName = "Keanu", lastName = "Reeves" },
        new Employee { birthYear = 1968, firstName = "Owen", lastName = "Wilson" },
        new Employee { birthYear = 1960, firstName = "James", lastName = "Spader" },
        new Employee { birthYear = 1964, firstName = "Sandra", lastName = "Bullock" },
      };

        return (actors);
    }
}
public class MainClass {
    public static void Main() {
        int oldestEmployeeAge = Employee.GetEmployees().Min(a => a.birthYear);
        Console.WriteLine(oldestEmployeeAge);
    }
}
开发者ID:C#程序员,项目名称:System.Linq,代码行数:27,代码来源:Queryable.Min


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