本文整理匯總了C#中System.Linq.Enumerable.First方法的典型用法代碼示例。如果您正苦於以下問題:C# Enumerable.First方法的具體用法?C# Enumerable.First怎麽用?C# Enumerable.First使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了Enumerable.First方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1:
int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54,
83, 23, 87, 435, 67, 12, 19 };
int first = numbers.First();
Console.WriteLine(first);
輸出:
9
示例2:
int[] numbers = { 9, 34, 65, 92, 87, 435, 3, 54,
83, 23, 87, 435, 67, 12, 19 };
int first = numbers.First(number => number > 80);
Console.WriteLine(first);
輸出:
92
示例3: Main
//引入命名空間
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 jones = presidents.Where(n => n.Equals("H")).First();
if (jones != null)
Console.WriteLine("H was found");
else
Console.WriteLine("H was not found");
}
}