文档介绍:101个LINQ例子
Restriction Operators Where - Simple 1 public void Linql () { int [] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 } ; var lowNums = from n in numbers where n < 5 select n;
Console. WriteLine(\ foreach (var x in lowNums) Console. WriteLine(x); } }
Where - Simple 2 public void Linq2() {
List products = GetProductList(); var soldOutProducts = from p in products where p. UnitsInStock == 0 select p;
Console. WriteLine(\
foreach (var product in soldOutProducts) {
Console. WriteLine (\ } }
Where - Simple 3 public void Linq3() {
List products = GetProductList 0; var expensivelnStockProducts = from p in products
where p. UnitsInStock > 0 && p. UnitPrice > 3. OOM select p;
Console. WriteLine (\ foreach (var product in expensivelnStockProducts) { Console. WriteLine(\ }
)
Where - Drilldown public void Linq4() {
var waCustomers =
List customers = GetCustomerList();
from c in customers where c. Region == \
select c;
Console. WriteLine(\ foreach (var customer in waCustomers) { Console. WriteLine(\customer. CompanyName);
foreach (var order in customer. Orders) {
Console. WriteLine(\. OrderDate); } } }
Where - Indexed public void Linq5() {
string"! digits = { \ var shortDigits = digits. Where((digit, index)=> digit. Length < index); Console. WriteLine(\
foreach (var d in shortDigits) {
Console. WriteLine (\ ) }
Projection Operators
Select - Simple 1 public voi