C # LINQ & XML

Source: Internet
Author: User

LINQ (language-integrated Query) is a language pattern used as a lookup, Access database, or XML file.

Is the way to communicate object-oriented languages and databases. very similar to SQL.

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;//LINQ namespacenamespaceprogramming_csharp{//Simple Customer Class     Public classCustomer//Define a Customer object that forms the collection to search    {         Public stringFirstName {Get;Set; }  Public stringLastName {Get;Set; }  Public stringEmailAddress {Get;Set; } //Overrides the object.tostring () to provide a//string representation of the object properties.         Public Override stringToString () {return string. Format ("{0} {1}\nemail: {2}", FirstName, LastName, EmailAddress); }    }
//Create a customer list with sample dataPrivate  StaticList<customer>createcustomerlist () {List<Customer> customers =NewList<customer>   {      NewCustomer {FirstName ="Orlando ", LastName ="Gee",EmailAddress ="[email protected]"},      NewCustomer {FirstName ="Keith ", LastName ="Harris",EmailAddress ="[email protected]" },      NewCustomer {FirstName ="Donna ", LastName ="Carreras",EmailAddress ="[email protected]" },      NewCustomer {FirstName ="Janet ", LastName ="Gates",EmailAddress ="[email protected]" },      NewCustomer {FirstName ="Lucy ", LastName ="Harrington",EmailAddress ="[email protected]" }    }; returncustomers; }

An in-memory collection that makes up the customer

   Static voidMain ()//Main Program{List<Customer> customers =createcustomerlist (); //Find Customer by First nameienumerable<customer> result = fromCustomerinchCustomerswhereCustomer. FirstName = ="Donna"        SelectCustomer//Select on the lastConsole.WriteLine ("FirstName = = \ "Donna\""); foreach(Customer Customerinchresult) {Console.WriteLine (Customer.  ToString ());} //Show Resultscustomers[3]. FirstName ="Donna";//Modifying DataConsole.WriteLine ("FirstName = = \ "Donna\" ( take both)");//Show Results      foreach(Customer Customerinchresult) {Console.WriteLine (Customer.    ToString ());} }  }}//namespace

Join keyword

Connect two data tables connected by the HYPHEN keyword

[Data source 1] Join [data source 2] on [join condition]

LINQ contains Keywords

Where from select and so on

A Where expression filter condition similar to SQL

From indicates the specified range

Select indicates lookup mappings

var keyword

The var universal data type must be initialized

var 1234 ; var " 1234 " ; var New Class1;

C # LINQ & XML

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.