Look at the code implementation:
1 using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 7 namespace Test8 {9 Class ProgramTen { OneStaticvoidMain (string[] args) A { -List<test> ListData =NewList<test>{ - NewTest {Name = "jiangjing", age = $, Sex = "Boy"}, the NewTest {Name = "wenting", age = +, Sex = "Girl"}, - NewTest {Name = "caihong", age = +, Sex = "Boy"}, - NewTest {Name = "Caiyun", age = +, Sex = "Boy"} - }; + - //string[] names = {"Jiangjing", "wenting", "Caihong", "test"}; + //1. How to use Query A //var res = from N in Names at //where N.endswith ("G") - //n.substring (n.length-1) - //select N; - - //2. How to use the method - //var res = names. (N=>n). Where (N=>n.endswith ("G")); in //foreach (var name in res) - //Console.WriteLine (name); to + //3. Use of aggregation functions, analysis of large data results - //var resultdata = Listdata.where (t=>t.age<20). Select (t=>t.age); the * //4. Projection: Create a new object in the query $ //var resultdata = listdata.where (t = = T.sex = "Boy"). Select (t = new {Name = T.name, age = T.age});Panax Notoginseng //foreach (var item in Resultdata) - //Console.WriteLine (item); the + //5. Single-Value selection: Distinct () function A //var resultdata = listdata.where (t = = T.sex = "Boy"). Select (t = new {Name = T.name, age = T.age}). Distinct (); the //foreach (var item in Resultdata) + //Console.WriteLine (item); - $ //6.Any and All methods $ //bool Falg1 = Resultdata.any (t=>t.name== "jiangjing"); - //bool falg2 = resultdata.all (t = = T.name = = "Jiangjing"); - //Console.Write ("{0} {1}", Falg1, falg2); the - //7. Multi-level sorting, using the method also line Orderby,thenby ..., but it's not as clear as it sounds .Wuyi //var resultdata = from T in ListData the //T.age, T.name - //Select New {Name = T.name, age = t.age}; Wu //foreach (var item in Resultdata) - //Console.WriteLine (item); About $ //8. Combination Query - //var resultdata = from T in ListData - //Group T by T.sex into TG - //Select New {sumage = TG. Sum (t = t.age), Sex = TG. Key}; A + //foreach (var item in Resultdata) the //Console.WriteLine (item); - $ //9. Query results using the Take function or the Skip function the the //var resultdata = Listdata.where (t=>t.age<20); the the //foreach (var item in Resultdata.take (1))//take function is the first n of a result set - //Console.WriteLine (item); in the //foreach (var item in Resultdata.skip (1))//skip function skips the first n of a result set the //Console.WriteLine (item); About the Console.readkey (); the } the } + - class Test the {Bayi Public string Name {get; set;} thePublicintAge {get; set;} the - Public string Sex {get; set;} - the Public override String ToString () the { the return"Name:" + name + "\ n" + "Age:" +Age ; the } - } the}
Select query related in C #