一篇文章带你全面解析Linq架构

文摘   2024-05-27 09:24   上海  
本文我们将介绍LINQ的整个体系结构,如下图所示,下图来源于,https://www.linkedin.com/feed/update/urn:li:activity:6971346130747977728/ 

接下来我们对思维导图中的方法进行简单讲解

1. Merging

1.1 Join 

定义:基于匹配键将两个序列的元素进行关联,类似于T-SQL中Join
Join方法源代码地址:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Join.cs#L11C13-L11C99
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.join?view=net-9.0

1.2 Zip 
定义:将指定的函数应用于两个序列中的对应元素,生成一个结果序列。
Zip方法源代码地址:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Zip.cs#L12C13-L27C63
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.zip?view=net-9.0

1.3 GroupJoin

定义:基于匹配的键关联两个序列,并对结果进行分组

GroupJoin方法源代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.groupjoin?view=net-9.0

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.groupjoin?view=net-9.0

‍‍2. Conversion
2.1 ToList
定义:根据IEnumerable<T>创建一个List<T>

ToList方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/ToCollection.cs#L51C13-L61C46

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.tolist?view=net-9.0

2.2 OfType

定义:基于指定的类型过滤IEnumerable

OfType方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Cast.cs#L13C13-L18C52

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.oftype?view=net-9.0

2.3 ToArray

定义:从IEnumerable<T>创建一个Array

ToArray方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/ToCollection.cs#L14C13-L45C31
ToArray示例代码地址:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.toarray?view=net-9.0

2.4 ToLookup
定义:从IEnumerable<T>创建一个Lookup<TKey,TElement>
ToLookup方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Lookup.cs#L36C13-L36C75
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.toarray?view=net-9.0

2.5 ToDictionary
定义:从IEnumerable<T>创建一个Dictionary<TKey,TValue>
ToDictionary方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/ToCollection.cs#L91C13-L96C42
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.todictionary?view=net-9.0

2.6 Cast
定义:转化IEnumerable到指定的类型
Cast方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Cast.cs#L38C13-L48C50

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.cast?view=net-9.0

3. Projection
3.1 Select

定义: 将序列的每个元素投影为新形式。

Select方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Select.cs#L71C13-L86C53

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.select?view=net-9.0

3.2 SelectMany

定义:将序列的每个元素投影到IEnumerable<T>并将结果序列平展为一个序列。

SelectMany方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/SelectMany.cs#L112C13-L132C83

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.selectmany?view=net-9.0

4. Aggregation

4.1 TryGetNonEnumeratedCount

定义:尝试确定序列中的元素数量而不强制枚举。

TryGetNonEnumeratedCount方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Count.cs#L97C13-L125C26

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.trygetnonenumeratedcount?view=net-9.0

4.2 Average

定义:计算序列的平均值

Average方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Average.cs#L76C72-L76C117

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.average?view=net-9.0

4.3 Aggregate(By)

定义:对序列应用累加器函数。指定的种子值用作累加器的初始值,而指定的函数用于选择结果值。

Average方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Aggregate.cs#L62C13-L83C43

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.aggregate?view=net-9.0

AverageBy方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/AggregateBy.cs#L18C13-L36C86
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.aggregateby?view=net-9.0

4.4 Max(By)

定义:返回序列中的最大值

Max方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Max.cs#L24C66-L24C84
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.max?view=net-9.0

Max(By)方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Max.cs#L419C123-L419C155

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.maxby?view=net-9.0

4.5 Min(By)

定义:返回序列中的最小值

Min方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Min.cs#L24C66-L24C84

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.min?view=net-9.0

MinBy方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Min.cs#L397C123-L397C165
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.minby?view=net-9.0

4.6 LongCount

定义:返回序列中元素的数量,返回的是Int64类型

LongCount方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Count.cs#L130C13-L147C26

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.longcount?view=net-9.0

4.7 Sum

定义:计算序列中数字值的总和

Sum方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Sum.cs#L18C68-L18C101
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.sum?view=net-9.0

5. Set

5.1 Union
定义:计算两个序列的并集,如果两个序列中出现相同值,则会进行去重
Union方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Union.cs#L12C124-L12C160
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.union?view=net-9.0

5.2 Intersect(By)

定义:计算两个序列的交集
Intersect方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Intersect.cs#L10C128-L10C158
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.intersect?view=net-9.0

IntersectBy方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Intersect.cs#L60C13-L73C78

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.intersectby?view=net-9.0

5.3 Except(By)

定义:计算两个序列的差集

Except方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Except.cs#L12C13-L22C56

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.except?view=net-9.0

ExceptBy方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Except.cs#L49C163-L49C205

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.exceptby?view=net-9.0

6. Quantification

6.1 Any

定义:判断序列中是否存在元素

Any方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/AnyAll.cs#L12C13-L14C40
示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.any?view=net-9.0

6.2 All

定义:确定序列中的所有元素是否都满足指定的条件。

All方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/AnyAll.cs#L48C13-L67C10

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.all?view=net-9.0

6.3 Contains

定义:确定序列是否包含一个指定的元素

Contains方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Contains.cs#L11C13-L12C42

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.contains?view=net-9.0

6.4 SequenceEqual 

定义:比较两个序列中元素的相等性,这里比较引用的相等性

SequenceEqual方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/SequenceEqual.cs#L11C13-L11C47

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.sequenceequal?view=net-9.0

7. Squence

7.1 Repeat

定义:生成一个序列包含相同的值

Repeat方法源代码https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Repeat.cs#L13C13-L23C64

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.repeat?view=net-9.0

7.2 Range

定义:在指定范围内生成一个整数的序列

Range方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Range.cs#L13C13-L24C52

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.range?view=net-9.0

7.3 Prepend
定义:在序列的开始位置添加一个值

Prepend方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/AppendPrepend.cs#L25C13-L32C90

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.prepend?view=net-9.0

7.4 Reverse

定义:反转序列中的元素

Reverse方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Reverse.cs#L13C13-L23C57

示例代码

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.reverse?view=net-9.0

7.5 Append

定义:在序列的末尾添加一个值

Append方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/AppendPrepend.cs#L13C13-L20C89

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.append?view=net-9.0

7.6 Empty

定义:返回一个具有指定类型参数的空IEnumerable

Empty方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Enumerable.cs#L16C13-L16C35

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.empty?view=net-9.0


7.7 Chunk
定义:将序列分割为指定大小的chunk块

Chunk方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Chunk.cs#L38C13-L53C48

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.chunk?view=net-9.0

8. Order
8.1 Order(Descending)

定义:对序列中的元素进行升序或降序排列

Order方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/OrderBy.cs#L46C13-L48C76

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.order?view=net-9.0

OrderDescending方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/OrderBy.cs#L72C13-L72C52

示例代码

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.orderdescending?view=net-9.0


8.2 OrderBy(Descending)

定义:根据指定的条件对序列中的元素进行升序或降序排列

OrderBy方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/OrderBy.cs#L51C16-L51C92

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.orderby?view=net-9.0

OrderByDescending方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/OrderBy.cs#L96C13-L96C88

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.orderbydescending?view=net-9.0

8.3 ThenBy

定义:根据一个键在序列的后续排序中进行升序排列,与之对应的降序排列是ThenByDescending

ThenBy方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/OrderBy.cs#L103C13-L108C77

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.thenby?view=net-9.0

9. Element
9.1 DefaultIfEmpty

定义:返回一个 IEnumerable<T> 的元素,如果序列为空,则返回一个具有默认值的单元素集合。

DefaultIfEmpty方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.cs#L12C13-L12C44

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.defaultifempty?view=net-9.0

9.2 Last(OrDefault)

定义:返回序列的最后一个元素

Last方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Last.cs#L13C13-L19C26

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.last?view=net-9.0

LastOrDefault方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Last.cs#L34C13-L34C37

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.lastordefault?view=net-9.0

9.3 ElementAt(OrDefault)

定义:返回序列中指定索引位置的元素

ElementAt方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/ElementAt.cs#L14C13-L37C28

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.elementat?view=net-9.0

ElementAtOrDefault方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/ElementAt.cs#L109C13-L125C28

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.elementatordefault?view=net-9.0

9.4 Single(OrDefault)

定义:返回序列中单个元素

Single方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Single.cs#L23C13-L29C28

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.single?view=net-9.0

SingleOrDefault方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Single.cs#L33C16-L33C42

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.singleordefault?view=net-9.0

9.5 First(OrDefault)

定义:返回序列中的第一个元素

First方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/First.cs#L13C13-L19C27

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.first?view=net-9.0

FirstOrDefault方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/First.cs#L60C13-L61C50

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.firstordefault?view=net-9.0

10. Grouping
10.1 GroupBy

定义:对序列中的元素进行分组

GroupBy方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Grouping.cs#L92C13-L92C90

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.groupby?view=net-9.0

10.2 CountBy

定义:根据指定的条件对集合中的元素进行分组并根据分组计算数量

CountBy方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/CountBy.cs#L13C13-L27C70

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.groupby?view=net-9.0

11.Filtering
11.1 SkipLast

定义:从元素的结尾跳过指定数量的元素并将剩余的元素返回

SkipLast方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Skip.cs#L131C13-L141C63

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.skiplast?view=net-9.0

11.2 TakeLast

定义:返回一个新的序列,包含了最后N个元素的集合

TakeLast方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Take.cs#L264C13-L273C59

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.takelast?view=net-9.0

11.3 Where

定义:根据指定条件过滤序列中的元素

Where方法源代码:hhttps://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Where.cs#L14C13-L44C76

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.where?view=net-9.0

11.4 Take(While)

定义:从序列的开始位置返回指定数量的连续元素。

Take方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Take.cs#L13C13-L20C45

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.take?view=net-9.0

TakeWhile方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Take.cs#L225C13-L240C57

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.takewhile?view=net-9.0

11.5 Skip(While)

定义:跳过序列中指定数量的元素,返回剩余的元素

Skip方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Skip.cs#L12C13-L38C48

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.skip?view=net-9.0

SkipWhile方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Skip.cs#L43C13-L58C57

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.skipwhile?view=net-9.0

11.6 Distinct(By)

定义:返回序列中不同的元素

Distinct方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Distinct.cs#L15C13-L25C68

示例代码:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.distinct?view=net-9.0

DistinctBy方法源代码:https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Linq/src/System/Linq/Distinct.cs#L39C140-L39C177
github: https://github.com/bingbing-gui

参考文章:https://www.linkedin.com/feed/update/urn:li:activity:6971346130747977728/

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable?view=net-9.0

桂迹
分享原创,记录痕迹!
 最新文章