當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。