本文整理汇总了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);
}
输出:
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);
输出:
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();
}
}
示例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);
}
}