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.