LINQ: starts to use LINQ (4)-LINQ to query the type relation of the operation.

Source: Internet
Author: User

LINQ: starts to use LINQ (4)-LINQ to query the type relation of the operation.
Start to use LINQ (4)-the type Relationship of the LINQ query operation.

The data source, query itself, and query execution are strongly-typed. The types of variables in the query must be the same as those of the elements in the data source.ForeachThe types of iteration variables in the statement are compatible. This strong type ensures that type errors are captured during compilation so that they can be corrected before the user encounters these errors.

1. Query of source data without conversion

This example does not show how to query the converted data by using the LINQ to Objects method. The source contains a string sequence, and the query output is also a string sequence.


Ii. Query of conversion source data

This example shows how to execute a simple-to-SQL query operation on data. The query uses a sequence of Customer objects as input and selects only the Name attribute in the result. Because Name is a string, the query generates a string sequence as the output.

Demonstrate another type of conversion.SelectThe statement returns the anonymous type of only two members of the original Customer object.


3. Let the compiler deduce the type information

You can also choose to have the compiler perform all the work for you. The keyword var can be used to query any local variable in an operation. However, the compiler provides a strong type for each variable in the query operation.





[Source] the text and images in this article are mainly taken from Microsoft official documents.

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: 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.