Query operations on LINQ topics

Source: Internet
Author: User

In the previous chapter we focused on LINQ query expressions, and LINQ provided some basic query expressions, as well as dozens of query operations. such as filtering operations, aggregation operations, projection operations and so on. These query operations make it easier to work with data sources.

LINQ provides dozens of query operations, most of which are for sequences that implement the iqueryable<t> and Ienumerbale<t> interfaces.

Serial number Query operations The corresponding query expression         description                                                                                                                                                   
1 Aggregate Custom Aggregation Operations
2 All Detects whether all elements in a sequence meet the specified criteria
3 Any Detects if there are elements in the sequence that meet the specified criteria
4 Average Calculates the average of all elements in a sequence
5 Cast Converts an element type in a sequence to a specified type
6 Contact Appends all elements of a sequence to another sequence and forms a new sequence
7 Contains Detects if the specified element exists in the sequence
8 Count Calculates the number of all elements in a sequence or calculates the number of elements that meet certain criteria
9 DefaultIfEmpty Returns a sequence of type ienumerable<t> that returns a sequence containing only one element if the sequence is empty (the value is the default value or the specified value)
10 Distinct Duplicate elements in the data source can be stripped back to a new sequence, and a comparer can be specified to compare whether two elements are equal
11 Element Returns the element at the specified index in the collection
12 Elementatordefault Returns the element at the specified index in the collection, returning the default value if the index is out of range
13 Empty Returns an empty sequence of type ienumerable<t>
14 Equalall/sequenceequal Determine if two sequences are equal
15 Except Computes the difference set of two sets (a collection of elements that belong to one collection and not to another collection)
16 First Returns the first element of a collection or returns the first element that satisfies a condition
17 FirstOrDefault Returns the first element of the collection, or returns the first element that satisfies the condition, or returns a default value if there are no elements that satisfy the condition.
18 GroupBy Group clause Group elements in a sequence
19 GroupJoin Join clause

Generates a hierarchical data structure that matches all elements in the first sequence with the related elements in the second sequence, and in the query results, the elements in the first collection appear, if the elements in the first sequence are related to the elements in the second sequence

Match, then the found element is used otherwise null

20 Intersect You can calculate the intersection of two sets, that is, the elements in the new collection exist with the first collection and the second collection
21st Join Join clause Similar to inner join in SQL Server, requires that the join relationship of an element must satisfy both the two data sources being joined
22 Last Returns the last element of the collection, or returns the last element that satisfies the specified condition
23 LastOrDefault Returns the last element of the collection, or returns the last element that satisfies the specified condition, or returns a default value if the element does not exist
24 LongCount Calculates the number of elements in a collection, or the number of elements that meet a specified condition, typically used to calculate the number of elements in a large collection
25 Max Calculates the maximum value of an element in a sequence
26 Min Calculates the minimum value of an element in a sequence
27 OfType Filters the elements of a specified type from a sequence and constructs it as a sequence
28 By ORDER BY clause Sort the elements in a sequence in ascending order based on the keyword
29 OrderByDescending ORDER BY clause Sort the elements in a sequence in descending order based on the keyword
30 Range Returns a sequence of numbers for a specified range
31 Repeat Returns a sequence containing duplicate values of type ienum<t>
32 Reverse Invert elements in a sequence
33 Select SELECT clause Projects the elements in the data source into a new sequence and specifies the type and representation of the element,
34 SelectMany Multiple from clauses Casts an element from the data source into a new sequence and specifies the type and representation of the element, but SelectMany can apply a function over multiple sequences and merge the results into a sequence
35 Single Returns the only element in the collection or returns the only element that satisfies the specified condition
36 Singleordefault Returns the only element in the collection, or returns the only element that satisfies the specified condition, and returns the default value if the element does not exist
37 Skip Skips a specified number of elements in a sequence, and then returns a sequence of the remaining elements
38 SkipWhile Skips a specified number of elements in a sequence, and then returns a sequence of the remaining elements
39 Sum Computes the and of all the elements in the sequence
40 Take Gets the specified number of elements from the beginning of the data source, and then returns a new sequence of these elements
41 TakeWhile Gets the specified number of elements from the beginning of the data source, and then returns a new sequence of these elements
42 ThenBy ORDER BY clause Sort sequences in ascending order based on secondary keywords
43 ThenByDescending ORDER BY clause Sort sequences in ascending order based on secondary keywords
44 ToArray Convert a sequence of type ienumerable<t> to an array of type t[]
45 ToDictionary Converts a sequence of type ienumerable<t> to an array of type dictionary<tkey,tvalue>
46 ToList Converts a sequence of type ienumerable<t> to an array of type list<t>
47 ToLookup Puts the elements of a sequence into a one-to-many dictionary sequence by key value lookup<tkey,tvalue>
48 Union Computes the set of two sets, consisting of a sequence of elements that belong to the first collection or to a second set
49 Where Where clause Processing logical operators to filter data from the data source

Query operations on LINQ topics

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.