本文整理匯總了C#中System.Linq.Queryable.First方法的典型用法代碼示例。如果您正苦於以下問題:C# Queryable.First方法的具體用法?C# Queryable.First怎麽用?C# Queryable.First使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了Queryable.First方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1:
int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54,
83, 23, 87, 435, 67, 12, 19 };
int first = numbers.AsQueryable().First();
Console.WriteLine(first);
輸出:
9
示例2:
int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54,
83, 23, 87, 435, 67, 12, 19 };
// Get the first number in the array that is greater than 80.
int first = numbers.AsQueryable().First(number => number > 80);
Console.WriteLine(first);
輸出:
92
示例3: Main
//引入命名空間
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
public class MainClass{
public static void Main(){
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var query = numbers.First();
Console.WriteLine("The first element in the sequence");
Console.Write(query);
query = numbers.Last();
Console.WriteLine("The last element in the sequence");
Console.Write(query);
Console.WriteLine("The first even element in the sequence");
query = numbers.First(n => n % 2 == 0);
Console.Write(query);
Console.WriteLine("The last even element in the sequence");
query = numbers.Last(n => n % 2 == 0);
Console.Write(query);
}
}
示例4: Queryable.First(filter)
//引入命名空間
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {
string[] presidents = {"G", "H", "a", "H", "over", "Jack"};
string name = presidents.First(p => p.StartsWith("H"));
Console.WriteLine(name);
}
}