C# LINQ Where 方法
Where 方法根據謂詞篩選陣列中的值。
在此,謂詞檢查大於 70 的元素。
Where((n, index) => n >= 70);
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] arr = { 10, 30, 20, 15, 90, 85, 40, 75 };
Console.WriteLine("Array:");
foreach (int a in arr)
Console.WriteLine(a);
// getting elements above 70
IEnumerable myQuery = arr.AsQueryable().Where((n, index) => n >= 70);
Console.WriteLine("Elements above 70...:");
foreach (int res in myQuery)
Console.WriteLine(res);
}
}輸出
Array: 10 30 20 15 90 85 40 75 Elements above 70...: 90 85 75
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP