本文整理汇总了C#中System.Linq.Queryable.Max方法的典型用法代码示例。如果您正苦于以下问题:C# Queryable.Max方法的具体用法?C# Queryable.Max怎么用?C# Queryable.Max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Queryable.Max方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MaxEx2
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
public static void MaxEx2()
{
Pet[] pets = { new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 } };
// Add Pet.Age to the length of Pet.Name
// to determine the "maximum" Pet object in the array.
int max =
pets.AsQueryable().Max(pet => pet.Age + pet.Name.Length);
Console.WriteLine(
"The maximum pet age plus name length is {0}.",
max);
}
输出:
The maximum pet age plus name length is 14.
示例2:
List<long> longs = new List<long> { 4294967296L, 466855135L, 81125L };
long max = longs.AsQueryable().Max();
Console.WriteLine("The largest number is {0}.", max);
输出:
The largest number is 4294967296.
示例3: Main
//引入命名空间
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
int[] myInts = new int[] { 974, 2, 7, 1374, 27, 54 };
int maxInt = myInts.Max();
Console.WriteLine(maxInt);
}
}
示例4: Queryable.Max(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 = "K", lastName = "R" },
new Employee { birthYear = 1968, firstName = "O", lastName = "W" },
new Employee { birthYear = 1960, firstName = "J", lastName = "S" },
new Employee { birthYear = 1964, firstName = "S", lastName = "B" },
};
return (actors);
}
}
public class MainClass {
public static void Main() {
int youngestEmployeeAge = Employee.GetEmployees().Max(a => a.birthYear);
Console.WriteLine(youngestEmployeeAge);
}
}