Use of C#linq

Source: Internet
Author: User

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.Xml.Linq;7 usingSystem.Collections;8 9 Ten namespaceLinqdemos One { A     class Program -     { -         Static voidMain (string[] args) the         { -             int[] num =New int[] {1,2,3,4,5,6,7,8,9, + }; -             varn = fromNumberinchNumwhereNumber%2==0 SelectNumber ; -             foreach(intAinchN) +             { - Console.WriteLine (a.tostring ()); +             } AArrayList arr =NewArrayList (); atArr. ADD (NewStudent {Name ="Zhang San", age = A, addresss ="Putian" }); -Arr. ADD (NewStudent {Name ="Wang San", age = A, addresss ="Fuzhou" }); -             vardata = fromStudent StuinchArrwhereStu. Name = ="Wang San" SelectStu; -             foreach(Student Iteminchdata) -             { - Console.WriteLine (item. Name); in             } -         } to     } +      Public classStudent -     { the          Public stringName {Get;Set; } *          Public intAge {Get;Set; } $          Public stringaddresss {Get;Set; }Panax Notoginseng  -     } the  +}

LINQ is an object-oriented approach to querying, and it is similar to SQL statements, and SQL is written in the SELECT * from table LINQ syntax from the N in data source select N;

Why not write the select together at the beginning of the statement with the same SQL notation? The main thing is to do when the IDE to consider the intelligent induction, the Select is written in the statement header is not conducive to the intelligent induction of the programming environment, the secret of its own Baidu understand Kazakhstan, this side unknown

The query object for LINQ can be all types that implement IEnumerable, such as arrays, database collections (Datatable,dataset ...), Arraylist,list,

The use of LINQ is more intuitive to us, but you can also use foreach and for. The efficiency and performance of LINQ execution is superior to those of the two query statements,

Linq>foreach>for

Use of C#linq

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.