可枚举序列操作
60 个节点
本页内容 60
全部满足
函数Whether every element passes a test; it stops at the first that does not. An empty sequence answers true.
全部满足 -> 真否
源: IEnumerable<TSource>
条件: Func<TSource, 真否>bool All(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to test. |
| 条件 | Func<TSource, 真否> | — | The test for each element. |
返回
| 结果 | 真否 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
存在任一项
函数重载 1/2
存在任一项(源: IEnumerable<TSource>) -> 真否
bool Any(IEnumerable<TSource> source)
Whether the sequence has any elements at all; it reads at most one, so it is the cheap way to test for emptiness.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to test. |
返回
| 结果 | 真否 |
重载 2/2
存在任一项 -> 真否
源: IEnumerable<TSource>
条件: Func<TSource, 真否>bool Any(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)Whether at least one element passes a test; it stops at the first that does. An empty sequence answers false.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to test. |
| 条件 | Func<TSource, 真否> | — | The test for each element. |
返回
| 结果 | 真否 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
追加
函数The sequence with one more element at the end; the source itself is not changed.
追加 -> IEnumerable<TSource>
源: IEnumerable<TSource>
元素: TSourceIEnumerable<TSource> Append(
IEnumerable<TSource> source,
TSource element)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to extend. |
| 元素 | TSource | — | The element to add after the last one. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
作为序列
函数Passes the sequence through unchanged but typed as a plain sequence, hiding its concrete collection type so that later steps treat it only as something to enumerate. A null input comes back as null.
作为序列(源: IEnumerable<TSource>) -> IEnumerable<TSource>
IEnumerable<TSource> AsEnumerable(IEnumerable<TSource> source)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to pass through. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
平均值
函数重载 1/20
平均值(源: IEnumerable<整数>) -> 数字
double Average(IEnumerable<int> source)
The mean of the numbers, as a double so that it keeps its fraction. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<整数> | — | The numbers to average. |
返回
| 结果 | 数字 |
重载 2/20
平均值(源: IEnumerable<大整数>) -> 数字
double Average(IEnumerable<long> source)
The mean of the numbers, as a double so that it keeps its fraction. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<大整数> | — | The numbers to average. |
返回
| 结果 | 数字 |
重载 3/20
平均值(源: IEnumerable<低精度数字>) -> 低精度数字
float Average(IEnumerable<float> source)
The mean of the numbers, worked out in double precision and rounded to float at the end. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<低精度数字> | — | The numbers to average. |
返回
| 结果 | 低精度数字 |
重载 4/20
平均值(源: IEnumerable<数字>) -> 数字
double Average(IEnumerable<double> source)
The mean of the numbers. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<数字> | — | The numbers to average. |
返回
| 结果 | 数字 |
重载 5/20
平均值(源: IEnumerable<高精度数字>) -> 高精度数字
decimal Average(IEnumerable<decimal> source)
The mean of the numbers, in decimal arithmetic. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<高精度数字> | — | The numbers to average. |
返回
| 结果 | 高精度数字 |
重载 6/20
平均值(源: IEnumerable<可选整数>) -> 可选数字
double? Average(IEnumerable<int?> source)
The mean of the numbers that are present, as a double; nulls are left out of both the total and the count, and an empty or all-null sequence gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选整数> | — | The numbers to average, some of which may be missing. |
返回
| 结果 | 可选数字 |
重载 7/20
平均值(源: IEnumerable<可选大整数>) -> 可选数字
double? Average(IEnumerable<long?> source)
The mean of the numbers that are present, as a double; nulls are left out of both the total and the count, and an empty or all-null sequence gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选大整数> | — | The numbers to average, some of which may be missing. |
返回
| 结果 | 可选数字 |
重载 8/20
平均值(源: IEnumerable<可选低精度数字>) -> 可选低精度数字
float? Average(IEnumerable<float?> source)
The mean of the numbers that are present, worked out in double precision and rounded to float; nulls are left out of both the total and the count, and an empty or all-null sequence gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选低精度数字> | — | The numbers to average, some of which may be missing. |
返回
| 结果 | 可选低精度数字 |
重载 9/20
平均值(源: IEnumerable<可选数字>) -> 可选数字
double? Average(IEnumerable<double?> source)
The mean of the numbers that are present; nulls are left out of both the total and the count, and an empty or all-null sequence gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选数字> | — | The numbers to average, some of which may be missing. |
返回
| 结果 | 可选数字 |
重载 10/20
平均值(源: IEnumerable<可选高精度数字>) -> 可选高精度数字
decimal? Average(IEnumerable<decimal?> source)
The mean of the numbers that are present, in decimal arithmetic; nulls are left out of both the total and the count, and an empty or all-null sequence gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选高精度数字> | — | The numbers to average, some of which may be missing. |
返回
| 结果 | 可选高精度数字 |
重载 11/20
平均值 -> 数字
源: IEnumerable<TSource>
选择器: Func<TSource, 整数>double Average(
IEnumerable<TSource> source,
Func<TSource, int> selector)The mean of a number worked out from each element, for example the average age of a list of people, as a double. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 整数> | — | Gives the number for each element. |
返回
| 结果 | 数字 |
重载 12/20
平均值 -> 数字
源: IEnumerable<TSource>
选择器: Func<TSource, 大整数>double Average(
IEnumerable<TSource> source,
Func<TSource, long> selector)The mean of a number worked out from each element, as a double. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 大整数> | — | Gives the number for each element. |
返回
| 结果 | 数字 |
重载 13/20
平均值 -> 低精度数字
源: IEnumerable<TSource>
选择器: Func<TSource, 低精度数字>float Average(
IEnumerable<TSource> source,
Func<TSource, float> selector)The mean of a number worked out from each element, worked out in double precision and rounded to float at the end. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 低精度数字> | — | Gives the number for each element. |
返回
| 结果 | 低精度数字 |
重载 14/20
平均值 -> 数字
源: IEnumerable<TSource>
选择器: Func<TSource, 数字>double Average(
IEnumerable<TSource> source,
Func<TSource, double> selector)The mean of a number worked out from each element. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 数字> | — | Gives the number for each element. |
返回
| 结果 | 数字 |
重载 15/20
平均值 -> 高精度数字
源: IEnumerable<TSource>
选择器: Func<TSource, 高精度数字>decimal Average(
IEnumerable<TSource> source,
Func<TSource, decimal> selector)The mean of a number worked out from each element, in decimal arithmetic. Throws System.InvalidOperationException when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 高精度数字> | — | Gives the number for each element. |
返回
| 结果 | 高精度数字 |
重载 16/20
平均值 -> 可选数字
源: IEnumerable<TSource>
选择器: Func<TSource, 可选整数>double? Average(
IEnumerable<TSource> source,
Func<TSource, int?> selector)The mean of a possibly missing number worked out from each element, as a double; nulls are left out of both the total and the count, and an empty sequence or all nulls gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 可选整数> | — | Gives the number for each element, or null to leave it out. |
返回
| 结果 | 可选数字 |
重载 17/20
平均值 -> 可选数字
源: IEnumerable<TSource>
选择器: Func<TSource, 可选大整数>double? Average(
IEnumerable<TSource> source,
Func<TSource, long?> selector)The mean of a possibly missing number worked out from each element, as a double; nulls are left out of both the total and the count, and an empty sequence or all nulls gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 可选大整数> | — | Gives the number for each element, or null to leave it out. |
返回
| 结果 | 可选数字 |
重载 18/20
平均值 -> 可选低精度数字
源: IEnumerable<TSource>
选择器: Func<TSource, 可选低精度数字>float? Average(
IEnumerable<TSource> source,
Func<TSource, float?> selector)The mean of a possibly missing number worked out from each element, in double precision rounded to float; nulls are left out of both the total and the count, and an empty sequence or all nulls gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 可选低精度数字> | — | Gives the number for each element, or null to leave it out. |
返回
| 结果 | 可选低精度数字 |
重载 19/20
平均值 -> 可选数字
源: IEnumerable<TSource>
选择器: Func<TSource, 可选数字>double? Average(
IEnumerable<TSource> source,
Func<TSource, double?> selector)The mean of a possibly missing number worked out from each element; nulls are left out of both the total and the count, and an empty sequence or all nulls gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 可选数字> | — | Gives the number for each element, or null to leave it out. |
返回
| 结果 | 可选数字 |
重载 20/20
平均值 -> 可选高精度数字
源: IEnumerable<TSource>
选择器: Func<TSource, 可选高精度数字>decimal? Average(
IEnumerable<TSource> source,
Func<TSource, decimal?> selector)The mean of a possibly missing number worked out from each element, in decimal arithmetic; nulls are left out of both the total and the count, and an empty sequence or all nulls gives null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to average over. |
| 选择器 | Func<TSource, 可选高精度数字> | — | Gives the number for each element, or null to leave it out. |
返回
| 结果 | 可选高精度数字 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
强制转换
函数Treats every element of an untyped sequence as a T Result, for when all elements are known to be of that type. Only reference and unboxing conversions are applied (a boxed int does not become a long), and an element that cannot be cast throws System.InvalidCastException when it is reached; use EnumerableRoutines.OfType to drop such elements instead.
强制转换(源: IEnumerable) -> IEnumerable<TResult>
IEnumerable<TResult> Cast(IEnumerable source)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable | — | The untyped sequence to cast. |
返回
| 结果 | IEnumerable<TResult> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
分块
函数Splits the sequence into consecutive batches of Size elements, for example to process items a page at a time; the last batch is shorter when the length is not a multiple of the size. Throws System.ArgumentOutOfRangeException when Size is less than 1.
分块 -> IEnumerable<TSource 数组>
源: IEnumerable<TSource>
大小: 整数IEnumerable<TSource[]> Chunk(
IEnumerable<TSource> source,
int size)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to split. |
| 大小 | 整数 | — | The number of elements in each batch. |
返回
| 结果 | IEnumerable<TSource 数组> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
连接序列
函数Joins two sequences end to end, keeping duplicates; use EnumerableRoutines.Union to merge without duplicates.
连接序列 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TSource>IEnumerable<TSource> Concat(
IEnumerable<TSource> first,
IEnumerable<TSource> second)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence whose elements come first. |
| 第二个 | IEnumerable<TSource> | — | The sequence whose elements follow. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
包含
函数重载 1/2
包含(源: IEnumerable<TSource>, 值: TSource) -> 真否
bool Contains(IEnumerable<TSource> source, TSource value)
Whether the sequence holds an element equal to Value, by the elements' default equality.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 值 | TSource | — | The value to look for. |
返回
| 结果 | 真否 |
重载 2/2
包含 -> 真否
源: IEnumerable<TSource>
值: TSource
比较器: IEqualityComparer<TSource>bool Contains(
IEnumerable<TSource> source,
TSource value,
IEqualityComparer<TSource> comparer)Whether the sequence holds an element equal to Value, with Comparer deciding equality (for example text compared without regard to case).
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 值 | TSource | — | The value to look for. |
| 比较器 | IEqualityComparer<TSource> | — | Decides whether two elements are equal; null uses the default equality. |
返回
| 结果 | 真否 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
计数
函数重载 1/2
计数(源: IEnumerable<TSource>) -> 整数
int Count(IEnumerable<TSource> source)
How many elements the sequence has. Throws System.OverflowException beyond Int32.MaxValue elements; use EnumerableRoutines.LongCount for sequences that long.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to count. |
返回
| 结果 | 整数 |
重载 2/2
计数 -> 整数
源: IEnumerable<TSource>
条件: Func<TSource, 真否>int Count(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)How many elements pass a test. Throws System.OverflowException beyond Int32.MaxValue matches.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to count in. |
| 条件 | Func<TSource, 真否> | — | Answers true for each element to count. |
返回
| 结果 | 整数 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
为空时取默认值
函数重载 1/2
为空时取默认值(源: IEnumerable<TSource>) -> IEnumerable<TSource>
IEnumerable<TSource> DefaultIfEmpty(IEnumerable<TSource> source)
The sequence unchanged when it has any elements; when it is empty, a sequence holding exactly one default value instead (null for reference and nullable types, zero or false for numbers and booleans), so that a later step always has something to work on.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence that might be empty. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
为空时取默认值 -> IEnumerable<TSource>
源: IEnumerable<TSource>
默认值: TSourceIEnumerable<TSource> DefaultIfEmpty(
IEnumerable<TSource> source,
TSource defaultValue)The sequence unchanged when it has any elements; when it is empty, a sequence holding exactly one Default Value instead, so that a later step always has something to work on.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence that might be empty. |
| 默认值 | TSource | — | The single element to give when Source is empty. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
去重
函数重载 1/2
去重(源: IEnumerable<TSource>) -> IEnumerable<TSource>
IEnumerable<TSource> Distinct(IEnumerable<TSource> source)
The sequence with repeated elements removed, comparing elements by their default equality; the first occurrence of each is kept, in the order they first appear.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to remove duplicates from. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
去重 -> IEnumerable<TSource>
源: IEnumerable<TSource>
比较器: IEqualityComparer<TSource>IEnumerable<TSource> Distinct(
IEnumerable<TSource> source,
IEqualityComparer<TSource> comparer)The sequence with repeated elements removed, using Comparer to decide which elements are the same (for example text compared without regard to case); the first occurrence of each is kept, in the order they first appear.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to remove duplicates from. |
| 比较器 | IEqualityComparer<TSource> | — | Decides whether two elements are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
按键去重
函数重载 1/2
按键去重 -> IEnumerable<TSource>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>IEnumerable<TSource> DistinctBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)One element per key, for example one person per surname: the first element seen with each key is kept, in their original order.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to remove duplicates from. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides whether two elements count as the same. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
按键去重 -> IEnumerable<TSource>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
比较器: IEqualityComparer<TKey>IEnumerable<TSource> DistinctBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> comparer)One element per key, with Comparer deciding which keys are the same; the first element seen with each key is kept, in their original order.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to remove duplicates from. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides whether two elements count as the same. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
指定位置的元素
函数The element at a position, counting from zero. Throws System.ArgumentOutOfRangeException when Index is negative or not less than the number of elements.
指定位置的元素(源: IEnumerable<TSource>, 索引: 整数) -> TSource
TSource ElementAt(IEnumerable<TSource> source, int index)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to read. |
| 索引 | 整数 | — | The zero-based position of the element. |
返回
| Result | TSource |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
指定位置的元素或默认值
函数The element at a position, counting from zero, or the type's default value (null for reference and nullable types, zero for numbers) when Index is negative or past the end.
指定位置的元素或默认值 -> TSource
源: IEnumerable<TSource>
索引: 整数TSource ElementAtOrDefault(
IEnumerable<TSource> source,
int index)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to read. |
| 索引 | 整数 | — | The zero-based position of the element. |
返回
| Result | TSource |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
空序列
函数A sequence with no elements, for use as a starting point or as a placeholder where a sequence input is required.
空序列() -> IEnumerable<TSource>
IEnumerable<TSource> Empty()
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
差集
函数重载 1/2
差集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TSource>IEnumerable<TSource> Except(
IEnumerable<TSource> first,
IEnumerable<TSource> second)The distinct elements of First that do not appear in Second, in the order of First. This is a set difference, so repeats within First are removed as well.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence to take elements from. |
| 第二个 | IEnumerable<TSource> | — | The elements to leave out. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
差集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TSource>
比较器: IEqualityComparer<TSource>IEnumerable<TSource> Except(
IEnumerable<TSource> first,
IEnumerable<TSource> second,
IEqualityComparer<TSource> comparer)The distinct elements of First that do not appear in Second, with Comparer deciding which elements are the same; repeats within First are removed as well.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence to take elements from. |
| 第二个 | IEnumerable<TSource> | — | The elements to leave out. |
| 比较器 | IEqualityComparer<TSource> | — | Decides whether two elements are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
按键求差集
函数重载 1/2
按键求差集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TKey>
键选择器: Func<TSource, TKey>IEnumerable<TSource> ExceptBy(
IEnumerable<TSource> first,
IEnumerable<TKey> second,
Func<TSource, TKey> keySelector)The elements of First whose key is not in a list of keys, for example everyone except the IDs in an exclusion list; one element per key, the first seen, in the order of First.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence to take elements from. |
| 第二个 | IEnumerable<TKey> | — | The keys to leave out. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element of First. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
按键求差集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TKey>
键选择器: Func<TSource, TKey>
比较器: IEqualityComparer<TKey>IEnumerable<TSource> ExceptBy(
IEnumerable<TSource> first,
IEnumerable<TKey> second,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> comparer)The elements of First whose key is not in a list of keys, with Comparer deciding which keys are the same; one element per key, the first seen.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence to take elements from. |
| 第二个 | IEnumerable<TKey> | — | The keys to leave out. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element of First. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
第一项
函数重载 1/2
第一项(源: IEnumerable<TSource>) -> TSource
TSource First(IEnumerable<TSource> source)
The first element. Throws System.InvalidOperationException when the sequence is empty; use EnumerableRoutines.FirstOrDefault to get a fallback instead.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to read. |
返回
| Result | TSource |
重载 2/2
第一项 -> TSource
源: IEnumerable<TSource>
条件: Func<TSource, 真否>TSource First(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)The first element that passes a test. Throws System.InvalidOperationException when none does.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 条件 | Func<TSource, 真否> | — | The test each element is checked against, in order. |
返回
| Result | TSource |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
第一项或默认值
函数重载 1/4
第一项或默认值(源: IEnumerable<TSource>) -> TSource
TSource FirstOrDefault(IEnumerable<TSource> source)
The first element, or the type's default value (null for reference and nullable types, zero for numbers) when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to read. |
返回
| Result | TSource |
重载 2/4
第一项或默认值 -> TSource
源: IEnumerable<TSource>
默认值: TSourceTSource FirstOrDefault(
IEnumerable<TSource> source,
TSource defaultValue)The first element, or Default Value when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to read. |
| 默认值 | TSource | — | What to give when there is no element. |
返回
| Result | TSource |
重载 3/4
第一项或默认值 -> TSource
源: IEnumerable<TSource>
条件: Func<TSource, 真否>TSource FirstOrDefault(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)The first element that passes a test, or the type's default value (null for reference and nullable types, zero for numbers) when none does.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 条件 | Func<TSource, 真否> | — | The test each element is checked against, in order. |
返回
| Result | TSource |
重载 4/4
第一项或默认值 -> TSource
源: IEnumerable<TSource>
条件: Func<TSource, 真否>
默认值: TSourceTSource FirstOrDefault(
IEnumerable<TSource> source,
Func<TSource, bool> predicate,
TSource defaultValue)The first element that passes a test, or Default Value when none does.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 条件 | Func<TSource, 真否> | — | The test each element is checked against, in order. |
| 默认值 | TSource | — | What to give when no element passes. |
返回
| Result | TSource |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
分组
函数重载 1/8
分组 -> IEnumerable<IGrouping<TKey, TSource>>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>IEnumerable<IGrouping<TKey, TSource>> GroupBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)Gathers elements that share a key into groups, for example orders by customer. Each group carries its key and its elements in their original order, and groups come in the order their keys first appear.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to group. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides each element's group. |
返回
| 结果 | IEnumerable<IGrouping<TKey, TSource>> |
重载 2/8
分组 -> IEnumerable<IGrouping<TKey, TSource>>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
比较器: IEqualityComparer<TKey>IEnumerable<IGrouping<TKey, TSource>> GroupBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> comparer)Gathers elements that share a key into groups, with Comparer deciding which keys are the same (for example names compared without regard to case). Groups come in the order their keys first appear.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to group. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides each element's group. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<IGrouping<TKey, TSource>> |
重载 3/8
分组 -> IEnumerable<IGrouping<TKey, TElement>>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
元素选择器: Func<TSource, TElement>IEnumerable<IGrouping<TKey, TElement>> GroupBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector)Gathers elements that share a key into groups, storing only the part of each element that Element Selector picks out, for example order amounts grouped by customer.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to group. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides each element's group. |
| 元素选择器 | Func<TSource, TElement> | — | Gives the value stored in the group for each element. |
返回
| 结果 | IEnumerable<IGrouping<TKey, TElement>> |
重载 4/8
分组 -> IEnumerable<IGrouping<TKey, TElement>>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
元素选择器: Func<TSource, TElement>
比较器: IEqualityComparer<TKey>IEnumerable<IGrouping<TKey, TElement>> GroupBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector,
IEqualityComparer<TKey> comparer)Gathers elements that share a key into groups, storing only the part of each element that Element Selector picks out, with Comparer deciding which keys are the same.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to group. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides each element's group. |
| 元素选择器 | Func<TSource, TElement> | — | Gives the value stored in the group for each element. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<IGrouping<TKey, TElement>> |
重载 5/8
分组 -> IEnumerable<TResult>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
结果选择器: Func<TKey, IEnumerable<TSource>, TResult>IEnumerable<TResult> GroupBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TKey, IEnumerable<TSource>, TResult> resultSelector)Groups elements by key and turns each group into a single result, for example one (customer, number of orders) value per customer.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to group. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides each element's group. |
| 结果选择器 | Func<TKey, IEnumerable<TSource>, TResult> | — | Receives a key and its group's elements and gives the result for that group. |
返回
| 结果 | IEnumerable<TResult> |
重载 6/8
分组 -> IEnumerable<TResult>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
结果选择器: Func<TKey, IEnumerable<TSource>, TResult>
比较器: IEqualityComparer<TKey>IEnumerable<TResult> GroupBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TKey, IEnumerable<TSource>, TResult> resultSelector,
IEqualityComparer<TKey> comparer)Groups elements by key and turns each group into a single result, with Comparer deciding which keys are the same.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to group. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides each element's group. |
| 结果选择器 | Func<TKey, IEnumerable<TSource>, TResult> | — | Receives a key and its group's elements and gives the result for that group. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TResult> |
重载 7/8
分组 -> IEnumerable<TResult>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
元素选择器: Func<TSource, TElement>
结果选择器: Func<TKey, IEnumerable<TElement>, TResult>IEnumerable<TResult> GroupBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector,
Func<TKey, IEnumerable<TElement>, TResult> resultSelector)Groups elements by key, keeps only the part of each element that Element Selector picks out, and turns each group into a single result, for example one (customer, total spent) value per customer.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to group. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides each element's group. |
| 元素选择器 | Func<TSource, TElement> | — | Gives the value kept in the group for each element. |
| 结果选择器 | Func<TKey, IEnumerable<TElement>, TResult> | — | Receives a key and its group's values and gives the result for that group. |
返回
| 结果 | IEnumerable<TResult> |
重载 8/8
分组 -> IEnumerable<TResult>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
元素选择器: Func<TSource, TElement>
结果选择器: Func<TKey, IEnumerable<TElement>, TResult>
比较器: IEqualityComparer<TKey>IEnumerable<TResult> GroupBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector,
Func<TKey, IEnumerable<TElement>, TResult> resultSelector,
IEqualityComparer<TKey> comparer)Groups elements by key, keeps only the part of each element that Element Selector picks out, and turns each group into a single result, with Comparer deciding which keys are the same.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to group. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides each element's group. |
| 元素选择器 | Func<TSource, TElement> | — | Gives the value kept in the group for each element. |
| 结果选择器 | Func<TKey, IEnumerable<TElement>, TResult> | — | Receives a key and its group's values and gives the result for that group. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TResult> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
分组连接
函数重载 1/2
分组连接 -> IEnumerable<TResult>
外部序列: IEnumerable<TOuter>
内部序列: IEnumerable<TInner>
外部键选择器: Func<TOuter, TKey>
内部键选择器: Func<TInner, TKey>
结果选择器: Func<TOuter, IEnumerable<TInner>, TResult>IEnumerable<TResult> GroupJoin(
IEnumerable<TOuter> outer,
IEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
Func<TOuter, IEnumerable<TInner>, TResult> resultSelector)Pairs each element of Outer with all the elements of Inner that share its key, for example each customer with their orders. Unlike Join, every outer element gives a result, with an empty collection when nothing matches, which makes this the basis of a left outer join.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 外部序列 | IEnumerable<TOuter> | — | The sequence that gives one result per element. |
| 内部序列 | IEnumerable<TInner> | — | The sequence whose elements are collected under matching outer elements. |
| 外部键选择器 | Func<TOuter, TKey> | — | Gives the key of each element of Outer. |
| 内部键选择器 | Func<TInner, TKey> | — | Gives the key of each element of Inner. |
| 结果选择器 | Func<TOuter, IEnumerable<TInner>, TResult> | — | Receives an outer element and its matching inner elements and gives the result. |
返回
| 结果 | IEnumerable<TResult> |
重载 2/2
分组连接 -> IEnumerable<TResult>
外部序列: IEnumerable<TOuter>
内部序列: IEnumerable<TInner>
外部键选择器: Func<TOuter, TKey>
内部键选择器: Func<TInner, TKey>
结果选择器: Func<TOuter, IEnumerable<TInner>, TResult>
比较器: IEqualityComparer<TKey>IEnumerable<TResult> GroupJoin(
IEnumerable<TOuter> outer,
IEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
Func<TOuter, IEnumerable<TInner>, TResult> resultSelector,
IEqualityComparer<TKey> comparer)Pairs each element of Outer with all the elements of Inner that share its key, with Comparer deciding which keys are equal; every outer element gives a result, with an empty collection when nothing matches.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 外部序列 | IEnumerable<TOuter> | — | The sequence that gives one result per element. |
| 内部序列 | IEnumerable<TInner> | — | The sequence whose elements are collected under matching outer elements. |
| 外部键选择器 | Func<TOuter, TKey> | — | Gives the key of each element of Outer. |
| 内部键选择器 | Func<TInner, TKey> | — | Gives the key of each element of Inner. |
| 结果选择器 | Func<TOuter, IEnumerable<TInner>, TResult> | — | Receives an outer element and its matching inner elements and gives the result. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TResult> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
交集
函数重载 1/2
交集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TSource>IEnumerable<TSource> Intersect(
IEnumerable<TSource> first,
IEnumerable<TSource> second)The distinct elements of First that also appear in Second, in the order of First.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence whose elements are kept. |
| 第二个 | IEnumerable<TSource> | — | The sequence an element must also appear in. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
交集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TSource>
比较器: IEqualityComparer<TSource>IEnumerable<TSource> Intersect(
IEnumerable<TSource> first,
IEnumerable<TSource> second,
IEqualityComparer<TSource> comparer)The distinct elements of First that also appear in Second, with Comparer deciding which elements are the same.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence whose elements are kept. |
| 第二个 | IEnumerable<TSource> | — | The sequence an element must also appear in. |
| 比较器 | IEqualityComparer<TSource> | — | Decides whether two elements are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
按键求交集
函数重载 1/2
按键求交集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TKey>
键选择器: Func<TSource, TKey>IEnumerable<TSource> IntersectBy(
IEnumerable<TSource> first,
IEnumerable<TKey> second,
Func<TSource, TKey> keySelector)The elements of First whose key appears in a list of keys, for example the people whose IDs are in a selection; one element per key, the first seen, in the order of First.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence whose elements are kept. |
| 第二个 | IEnumerable<TKey> | — | The keys an element's key must be among. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element of First. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
按键求交集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TKey>
键选择器: Func<TSource, TKey>
比较器: IEqualityComparer<TKey>IEnumerable<TSource> IntersectBy(
IEnumerable<TSource> first,
IEnumerable<TKey> second,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> comparer)The elements of First whose key appears in a list of keys, with Comparer deciding which keys are the same; one element per key, the first seen.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence whose elements are kept. |
| 第二个 | IEnumerable<TKey> | — | The keys an element's key must be among. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element of First. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
连接
函数重载 1/2
连接 -> IEnumerable<TResult>
外部序列: IEnumerable<TOuter>
内部序列: IEnumerable<TInner>
外部键选择器: Func<TOuter, TKey>
内部键选择器: Func<TInner, TKey>
结果选择器: Func<TOuter, TInner, TResult>IEnumerable<TResult> Join(
IEnumerable<TOuter> outer,
IEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
Func<TOuter, TInner, TResult> resultSelector)Matches elements of two sequences by key (an inner join), for example orders to their customers: every pair whose keys are equal gives one result. Elements with no match on the other side are left out, and null keys never match. Results follow the order of Outer, and within each, the order of Inner.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 外部序列 | IEnumerable<TOuter> | — | The first sequence to join. |
| 内部序列 | IEnumerable<TInner> | — | The sequence to match against. |
| 外部键选择器 | Func<TOuter, TKey> | — | Gives the key of each element of Outer. |
| 内部键选择器 | Func<TInner, TKey> | — | Gives the key of each element of Inner. |
| 结果选择器 | Func<TOuter, TInner, TResult> | — | Combines a matching pair into a result. |
返回
| 结果 | IEnumerable<TResult> |
重载 2/2
连接 -> IEnumerable<TResult>
外部序列: IEnumerable<TOuter>
内部序列: IEnumerable<TInner>
外部键选择器: Func<TOuter, TKey>
内部键选择器: Func<TInner, TKey>
结果选择器: Func<TOuter, TInner, TResult>
比较器: IEqualityComparer<TKey>IEnumerable<TResult> Join(
IEnumerable<TOuter> outer,
IEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
Func<TOuter, TInner, TResult> resultSelector,
IEqualityComparer<TKey> comparer)Matches elements of two sequences by key (an inner join), with Comparer deciding which keys are equal; every matching pair gives one result and unmatched elements are left out.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 外部序列 | IEnumerable<TOuter> | — | The first sequence to join. |
| 内部序列 | IEnumerable<TInner> | — | The sequence to match against. |
| 外部键选择器 | Func<TOuter, TKey> | — | Gives the key of each element of Outer. |
| 内部键选择器 | Func<TInner, TKey> | — | Gives the key of each element of Inner. |
| 结果选择器 | Func<TOuter, TInner, TResult> | — | Combines a matching pair into a result. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TResult> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
最后一项
函数重载 1/2
最后一项(源: IEnumerable<TSource>) -> TSource
TSource Last(IEnumerable<TSource> source)
The last element. Throws System.InvalidOperationException when the sequence is empty; use EnumerableRoutines.LastOrDefault to get a fallback instead.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to read. |
返回
| Result | TSource |
重载 2/2
最后一项 -> TSource
源: IEnumerable<TSource>
条件: Func<TSource, 真否>TSource Last(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)The last element that passes a test. Throws System.InvalidOperationException when none does.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 条件 | Func<TSource, 真否> | — | The test each element is checked against. |
返回
| Result | TSource |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
最后一项或默认值
函数重载 1/4
最后一项或默认值(源: IEnumerable<TSource>) -> TSource
TSource LastOrDefault(IEnumerable<TSource> source)
The last element, or the type's default value (null for reference and nullable types, zero for numbers) when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to read. |
返回
| Result | TSource |
重载 2/4
最后一项或默认值 -> TSource
源: IEnumerable<TSource>
默认值: TSourceTSource LastOrDefault(
IEnumerable<TSource> source,
TSource defaultValue)The last element, or Default Value when the sequence is empty.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to read. |
| 默认值 | TSource | — | What to give when there is no element. |
返回
| Result | TSource |
重载 3/4
最后一项或默认值 -> TSource
源: IEnumerable<TSource>
条件: Func<TSource, 真否>TSource LastOrDefault(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)The last element that passes a test, or the type's default value (null for reference and nullable types, zero for numbers) when none does.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 条件 | Func<TSource, 真否> | — | The test each element is checked against. |
返回
| Result | TSource |
重载 4/4
最后一项或默认值 -> TSource
源: IEnumerable<TSource>
条件: Func<TSource, 真否>
默认值: TSourceTSource LastOrDefault(
IEnumerable<TSource> source,
Func<TSource, bool> predicate,
TSource defaultValue)The last element that passes a test, or Default Value when none does.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 条件 | Func<TSource, 真否> | — | The test each element is checked against. |
| 默认值 | TSource | — | What to give when no element passes. |
返回
| Result | TSource |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
大整数计数
函数重载 1/2
大整数计数(源: IEnumerable<TSource>) -> 大整数
long LongCount(IEnumerable<TSource> source)
How many elements the sequence has, as a 64-bit number for sequences too long for EnumerableRoutines.Count.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to count. |
返回
| 结果 | 大整数 |
重载 2/2
大整数计数 -> 大整数
源: IEnumerable<TSource>
条件: Func<TSource, 真否>long LongCount(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)How many elements pass a test, as a 64-bit number.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to count in. |
| 条件 | Func<TSource, 真否> | — | Answers true for each element to count. |
返回
| 结果 | 大整数 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
最大值
函数重载 1/2
最大值(源: IEnumerable<TSource>) -> TSource
TSource Max(IEnumerable<TSource> source)
The largest element, by the elements' default comparison. For reference or nullable element types, nulls are ignored and an empty sequence (or one holding only nulls) gives null; for non-nullable value types such as plain numbers, an empty sequence throws System.InvalidOperationException.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search; its elements must be comparable. |
返回
| Result | TSource |
重载 2/2
最大值 -> TResult
源: IEnumerable<TSource>
选择器: Func<TSource, TResult>TResult Max(
IEnumerable<TSource> source,
Func<TSource, TResult> selector)The largest value that Selector gives for any element, for example the highest score in a list of players. For reference or nullable result types, nulls are ignored and an empty sequence gives null; for non-nullable value types such as plain numbers, an empty sequence throws System.InvalidOperationException.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 选择器 | Func<TSource, TResult> | — | Gives the comparable value for each element. |
返回
| Result | TResult |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
最小值
函数重载 1/2
最小值(源: IEnumerable<TSource>) -> TSource
TSource Min(IEnumerable<TSource> source)
The smallest element, by the elements' default comparison. For reference or nullable element types, nulls are ignored and an empty sequence (or one holding only nulls) gives null; for non-nullable value types such as plain numbers, an empty sequence throws System.InvalidOperationException.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search; its elements must be comparable. |
返回
| Result | TSource |
重载 2/2
最小值 -> TResult
源: IEnumerable<TSource>
选择器: Func<TSource, TResult>TResult Min(
IEnumerable<TSource> source,
Func<TSource, TResult> selector)The smallest value that Selector gives for any element, for example the lowest price in a list of items. For reference or nullable result types, nulls are ignored and an empty sequence gives null; for non-nullable value types such as plain numbers, an empty sequence throws System.InvalidOperationException.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 选择器 | Func<TSource, TResult> | — | Gives the comparable value for each element. |
返回
| Result | TResult |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
筛选类型
函数Keeps only the elements of an untyped sequence that are a T Result (or derive from it); nulls and elements of any other type are dropped, so unlike EnumerableRoutines.Cast it never throws for a mismatched element.
筛选类型(源: IEnumerable) -> IEnumerable<TResult>
IEnumerable<TResult> OfType(IEnumerable source)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable | — | The untyped sequence to filter. |
返回
| 结果 | IEnumerable<TResult> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
排序
函数The elements sorted from smallest to largest by their default comparison (numbers by value, text in the current culture's order). The sort is stable, so equal elements keep their original order; the elements must be comparable, otherwise sorting fails when the result is read.
排序(源: IEnumerable<TSource>) -> IEnumerable<TSource>
IEnumerable<TSource> Order(IEnumerable<TSource> source)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to sort. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
按键排序
函数重载 1/2
按键排序 -> IOrderedEnumerable<TSource>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>IOrderedEnumerable<TSource> OrderBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)Sorts elements from smallest to largest by a key worked out from each, for example people by age. The sort is stable, so elements with equal keys keep their original order; follow it with EnumerableRoutines.ThenBy to break ties with a second key.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to sort. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key to sort each element by. |
返回
| 结果 | IOrderedEnumerable<TSource> |
重载 2/2
按键排序 -> IOrderedEnumerable<TSource>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
比较器: IComparer<TKey>IOrderedEnumerable<TSource> OrderBy(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IComparer<TKey> comparer)Sorts elements from smallest to largest by a key worked out from each, with Comparer deciding how keys are ordered. The sort is stable, so elements with equal keys keep their original order.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to sort. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key to sort each element by. |
| 比较器 | IComparer<TKey> | — | Decides which of two keys comes first; null uses the key type's default comparison. |
返回
| 结果 | IOrderedEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
按键降序排序
函数重载 1/2
按键降序排序 -> IOrderedEnumerable<TSource>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>IOrderedEnumerable<TSource> OrderByDescending(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)Sorts elements from largest to smallest by a key worked out from each, for example scores from highest to lowest. The sort is stable, so elements with equal keys keep their original order.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to sort. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key to sort each element by. |
返回
| 结果 | IOrderedEnumerable<TSource> |
重载 2/2
按键降序排序 -> IOrderedEnumerable<TSource>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
比较器: IComparer<TKey>IOrderedEnumerable<TSource> OrderByDescending(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IComparer<TKey> comparer)Sorts elements from largest to smallest by a key worked out from each, with Comparer deciding how keys are ordered. The sort is stable, so elements with equal keys keep their original order.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to sort. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key to sort each element by. |
| 比较器 | IComparer<TKey> | — | Decides which of two keys comes first; null uses the key type's default comparison. |
返回
| 结果 | IOrderedEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
降序排序
函数The elements sorted from largest to smallest by their default comparison. The sort is stable, so equal elements keep their original order; the elements must be comparable, otherwise sorting fails when the result is read.
降序排序(源: IEnumerable<TSource>) -> IEnumerable<TSource>
IEnumerable<TSource> OrderDescending(IEnumerable<TSource> source)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to sort. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
前置
函数The sequence with one more element at the start; the source itself is not changed.
前置 -> IEnumerable<TSource>
源: IEnumerable<TSource>
元素: TSourceIEnumerable<TSource> Prepend(
IEnumerable<TSource> source,
TSource element)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to extend. |
| 元素 | TSource | — | The element to put before the first one. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
整数范围
函数A run of consecutive whole numbers: Count of them, starting at Start, so a start of 1 and a count of 10 gives 1 to 10. Throws System.ArgumentOutOfRangeException when Count is negative or the last number would exceed Int32.MaxValue.
整数范围(起点: 整数, 数量: 整数) -> IEnumerable<整数>
IEnumerable<int> Range(int start, int count)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 起点 | 整数 | — | The first number. |
| 数量 | 整数 | — | How many numbers to give; zero gives an empty sequence. |
返回
| 结果 | IEnumerable<整数> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
重复
函数A sequence holding the same value Count times. For a reference type every entry is the same object, not a copy. Throws System.ArgumentOutOfRangeException when Count is negative.
重复(元素: TResult, 数量: 整数) -> IEnumerable<TResult>
IEnumerable<TResult> Repeat(TResult element, int count)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 元素 | TResult | — | The value to repeat. |
| 数量 | 整数 | — | How many times to repeat it; zero gives an empty sequence. |
返回
| 结果 | IEnumerable<TResult> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
反转
函数The elements in reverse order. The whole source is read before the first result is given, and the source itself is not changed.
反转(源: IEnumerable<TSource>) -> IEnumerable<TSource>
IEnumerable<TSource> Reverse(IEnumerable<TSource> source)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to reverse. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
投影
函数重载 1/2
投影 -> IEnumerable<TResult>
源: IEnumerable<TSource>
选择器: Func<TSource, TResult>IEnumerable<TResult> Select(
IEnumerable<TSource> source,
Func<TSource, TResult> selector)Transforms each element through Selector, for example from a list of people to a list of their names.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to transform. |
| 选择器 | Func<TSource, TResult> | — | Gives the result for one element. |
返回
| 结果 | IEnumerable<TResult> |
重载 2/2
投影 -> IEnumerable<TResult>
源: IEnumerable<TSource>
选择器: Func<TSource, 整数, TResult>IEnumerable<TResult> Select(
IEnumerable<TSource> source,
Func<TSource, int, TResult> selector)Transforms each element through Selector, which also receives the element's position, for example to number the elements.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to transform. |
| 选择器 | Func<TSource, 整数, TResult> | — | Gives the result for one element and its zero-based position in Source. |
返回
| 结果 | IEnumerable<TResult> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
投影并展平
函数重载 1/4
投影并展平 -> IEnumerable<TResult>
源: IEnumerable<TSource>
选择器: Func<TSource, IEnumerable<TResult>>IEnumerable<TResult> SelectMany(
IEnumerable<TSource> source,
Func<TSource, IEnumerable<TResult>> selector)Turns each element into a sequence and joins all those sequences end to end into one flat sequence, for example from a list of folders to one list of all their files.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence whose elements each give a sequence. |
| 选择器 | Func<TSource, IEnumerable<TResult>> | — | Gives the sequence for one element. |
返回
| 结果 | IEnumerable<TResult> |
重载 2/4
投影并展平 -> IEnumerable<TResult>
源: IEnumerable<TSource>
选择器: Func<TSource, 整数, IEnumerable<TResult>>IEnumerable<TResult> SelectMany(
IEnumerable<TSource> source,
Func<TSource, int, IEnumerable<TResult>> selector)Turns each element, together with its position, into a sequence and joins all those sequences end to end into one flat sequence.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence whose elements each give a sequence. |
| 选择器 | Func<TSource, 整数, IEnumerable<TResult>> | — | Gives the sequence for one element and its zero-based position in Source. |
返回
| 结果 | IEnumerable<TResult> |
重载 3/4
投影并展平 -> IEnumerable<TResult>
源: IEnumerable<TSource>
集合选择器: Func<TSource, IEnumerable<TCollection>>
结果选择器: Func<TSource, TCollection, TResult>IEnumerable<TResult> SelectMany(
IEnumerable<TSource> source,
Func<TSource, IEnumerable<TCollection>> collectionSelector,
Func<TSource, TCollection, TResult> resultSelector)Flattens a sequence of sequences while keeping track of where each inner element came from: every inner element is combined with its source element by Result Selector, for example into (folder, file) pairs.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence whose elements each give a sequence. |
| 集合选择器 | Func<TSource, IEnumerable<TCollection>> | — | Gives the inner sequence for one element. |
| 结果选择器 | Func<TSource, TCollection, TResult> | — | Combines a source element with one of its inner elements into a result. |
返回
| 结果 | IEnumerable<TResult> |
重载 4/4
投影并展平 -> IEnumerable<TResult>
源: IEnumerable<TSource>
集合选择器: Func<TSource, 整数, IEnumerable<TCollection>>
结果选择器: Func<TSource, TCollection, TResult>IEnumerable<TResult> SelectMany(
IEnumerable<TSource> source,
Func<TSource, int, IEnumerable<TCollection>> collectionSelector,
Func<TSource, TCollection, TResult> resultSelector)Flattens a sequence of sequences while keeping track of where each inner element came from; like the other overload, but Collection Selector also receives each source element's position.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence whose elements each give a sequence. |
| 集合选择器 | Func<TSource, 整数, IEnumerable<TCollection>> | — | Gives the inner sequence for one element and its zero-based position in Source. |
| 结果选择器 | Func<TSource, TCollection, TResult> | — | Combines a source element with one of its inner elements into a result. |
返回
| 结果 | IEnumerable<TResult> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
唯一项
函数重载 1/2
唯一项(源: IEnumerable<TSource>) -> TSource
TSource Single(IEnumerable<TSource> source)
The one and only element, for when having exactly one is an expectation worth checking. Throws System.InvalidOperationException when the sequence is empty or has more than one element.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence expected to hold exactly one element. |
返回
| Result | TSource |
重载 2/2
唯一项 -> TSource
源: IEnumerable<TSource>
条件: Func<TSource, 真否>TSource Single(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)The one and only element that passes a test. Throws System.InvalidOperationException when no element passes or more than one does.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 条件 | Func<TSource, 真否> | — | The test exactly one element is expected to pass. |
返回
| Result | TSource |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
唯一项或默认值
函数重载 1/4
唯一项或默认值(源: IEnumerable<TSource>) -> TSource
TSource SingleOrDefault(IEnumerable<TSource> source)
The only element, or the type's default value (null for reference and nullable types, zero for numbers) when the sequence is empty. Still throws System.InvalidOperationException when there is more than one element.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence expected to hold at most one element. |
返回
| Result | TSource |
重载 2/4
唯一项或默认值 -> TSource
源: IEnumerable<TSource>
默认值: TSourceTSource SingleOrDefault(
IEnumerable<TSource> source,
TSource defaultValue)The only element, or Default Value when the sequence is empty. Still throws System.InvalidOperationException when there is more than one element.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence expected to hold at most one element. |
| 默认值 | TSource | — | What to give when there is no element. |
返回
| Result | TSource |
重载 3/4
唯一项或默认值 -> TSource
源: IEnumerable<TSource>
条件: Func<TSource, 真否>TSource SingleOrDefault(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)The only element that passes a test, or the type's default value (null for reference and nullable types, zero for numbers) when none does. Still throws System.InvalidOperationException when more than one passes.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 条件 | Func<TSource, 真否> | — | The test at most one element is expected to pass. |
返回
| Result | TSource |
重载 4/4
唯一项或默认值 -> TSource
源: IEnumerable<TSource>
条件: Func<TSource, 真否>
默认值: TSourceTSource SingleOrDefault(
IEnumerable<TSource> source,
Func<TSource, bool> predicate,
TSource defaultValue)The only element that passes a test, or Default Value when none does. Still throws System.InvalidOperationException when more than one passes.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to search. |
| 条件 | Func<TSource, 真否> | — | The test at most one element is expected to pass. |
| 默认值 | TSource | — | What to give when no element passes. |
返回
| Result | TSource |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
跳过
函数The sequence without its first Count elements. A count of zero or less gives the whole sequence, and a count at or beyond its length gives an empty one.
跳过 -> IEnumerable<TSource>
源: IEnumerable<TSource>
数量: 整数IEnumerable<TSource> Skip(
IEnumerable<TSource> source,
int count)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to skip into. |
| 数量 | 整数 | — | How many elements to leave out from the start. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
跳过末尾
函数The sequence without its last Count elements. A count of zero or less gives the whole sequence, and a count at or beyond its length gives an empty one.
跳过末尾 -> IEnumerable<TSource>
源: IEnumerable<TSource>
数量: 整数IEnumerable<TSource> SkipLast(
IEnumerable<TSource> source,
int count)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to trim. |
| 数量 | 整数 | — | How many elements to leave out from the end. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
条件跳过
函数重载 1/2
条件跳过 -> IEnumerable<TSource>
源: IEnumerable<TSource>
条件: Func<TSource, 真否>IEnumerable<TSource> SkipWhile(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)Leaves out elements from the start for as long as Predicate answers true, then gives the first element it rejected and every element after it, whether or not they would pass.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to skip into. |
| 条件 | Func<TSource, 真否> | — | Answers true for each leading element to leave out. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
条件跳过 -> IEnumerable<TSource>
源: IEnumerable<TSource>
条件: Func<TSource, 整数, 真否>IEnumerable<TSource> SkipWhile(
IEnumerable<TSource> source,
Func<TSource, int, bool> predicate)Leaves out elements from the start for as long as Predicate answers true, then gives the rest; the test also receives each element's position.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to skip into. |
| 条件 | Func<TSource, 整数, 真否> | — | Receives an element and its zero-based position, and answers true to leave it out. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
求和
函数重载 1/20
求和(源: IEnumerable<整数>) -> 整数
int Sum(IEnumerable<int> source)
The total of the numbers; an empty sequence gives 0. Throws System.OverflowException when the total does not fit in an int.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<整数> | — | The numbers to add up. |
返回
| 结果 | 整数 |
重载 2/20
求和(源: IEnumerable<大整数>) -> 大整数
long Sum(IEnumerable<long> source)
The total of the numbers; an empty sequence gives 0. Throws System.OverflowException when the total does not fit in a long.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<大整数> | — | The numbers to add up. |
返回
| 结果 | 大整数 |
重载 3/20
求和(源: IEnumerable<低精度数字>) -> 低精度数字
float Sum(IEnumerable<float> source)
The total of the numbers, added up in double precision and rounded to float at the end; an empty sequence gives 0, and a total too large for a float becomes infinity.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<低精度数字> | — | The numbers to add up. |
返回
| 结果 | 低精度数字 |
重载 4/20
求和(源: IEnumerable<数字>) -> 数字
double Sum(IEnumerable<double> source)
The total of the numbers; an empty sequence gives 0, and a total too large for a double becomes infinity.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<数字> | — | The numbers to add up. |
返回
| 结果 | 数字 |
重载 5/20
求和(源: IEnumerable<高精度数字>) -> 高精度数字
decimal Sum(IEnumerable<decimal> source)
The exact decimal total of the numbers; an empty sequence gives 0. Throws System.OverflowException when the total exceeds the decimal range.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<高精度数字> | — | The numbers to add up. |
返回
| 结果 | 高精度数字 |
重载 6/20
求和(源: IEnumerable<可选整数>) -> 可选整数
int? Sum(IEnumerable<int?> source)
The total of the numbers that are present; nulls are skipped, and an empty or all-null sequence gives 0, never null. Throws System.OverflowException when the total does not fit in an int.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选整数> | — | The numbers to add up, some of which may be missing. |
返回
| 结果 | 可选整数 |
重载 7/20
求和(源: IEnumerable<可选大整数>) -> 可选大整数
long? Sum(IEnumerable<long?> source)
The total of the numbers that are present; nulls are skipped, and an empty or all-null sequence gives 0, never null. Throws System.OverflowException when the total does not fit in a long.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选大整数> | — | The numbers to add up, some of which may be missing. |
返回
| 结果 | 可选大整数 |
重载 8/20
求和(源: IEnumerable<可选低精度数字>) -> 可选低精度数字
float? Sum(IEnumerable<float?> source)
The total of the numbers that are present, added up in double precision and rounded to float at the end; nulls are skipped, and an empty or all-null sequence gives 0, never null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选低精度数字> | — | The numbers to add up, some of which may be missing. |
返回
| 结果 | 可选低精度数字 |
重载 9/20
求和(源: IEnumerable<可选数字>) -> 可选数字
double? Sum(IEnumerable<double?> source)
The total of the numbers that are present; nulls are skipped, and an empty or all-null sequence gives 0, never null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选数字> | — | The numbers to add up, some of which may be missing. |
返回
| 结果 | 可选数字 |
重载 10/20
求和(源: IEnumerable<可选高精度数字>) -> 可选高精度数字
decimal? Sum(IEnumerable<decimal?> source)
The exact decimal total of the numbers that are present; nulls are skipped, and an empty or all-null sequence gives 0, never null. Throws System.OverflowException when the total exceeds the decimal range.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<可选高精度数字> | — | The numbers to add up, some of which may be missing. |
返回
| 结果 | 可选高精度数字 |
重载 11/20
求和 -> 整数
源: IEnumerable<TSource>
选择器: Func<TSource, 整数>int Sum(
IEnumerable<TSource> source,
Func<TSource, int> selector)The total of a number worked out from each element, for example the quantities in a list of order lines; an empty sequence gives 0. Throws System.OverflowException when the total does not fit in an int.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 整数> | — | Gives the number for each element. |
返回
| 结果 | 整数 |
重载 12/20
求和 -> 大整数
源: IEnumerable<TSource>
选择器: Func<TSource, 大整数>long Sum(
IEnumerable<TSource> source,
Func<TSource, long> selector)The total of a number worked out from each element; an empty sequence gives 0. Throws System.OverflowException when the total does not fit in a long.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 大整数> | — | Gives the number for each element. |
返回
| 结果 | 大整数 |
重载 13/20
求和 -> 低精度数字
源: IEnumerable<TSource>
选择器: Func<TSource, 低精度数字>float Sum(
IEnumerable<TSource> source,
Func<TSource, float> selector)The total of a number worked out from each element, added up in double precision and rounded to float at the end; an empty sequence gives 0.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 低精度数字> | — | Gives the number for each element. |
返回
| 结果 | 低精度数字 |
重载 14/20
求和 -> 数字
源: IEnumerable<TSource>
选择器: Func<TSource, 数字>double Sum(
IEnumerable<TSource> source,
Func<TSource, double> selector)The total of a number worked out from each element, for example the lengths of a list of segments; an empty sequence gives 0.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 数字> | — | Gives the number for each element. |
返回
| 结果 | 数字 |
重载 15/20
求和 -> 高精度数字
源: IEnumerable<TSource>
选择器: Func<TSource, 高精度数字>decimal Sum(
IEnumerable<TSource> source,
Func<TSource, decimal> selector)The exact decimal total of a number worked out from each element, for example the prices in a basket; an empty sequence gives 0. Throws System.OverflowException when the total exceeds the decimal range.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 高精度数字> | — | Gives the number for each element. |
返回
| 结果 | 高精度数字 |
重载 16/20
求和 -> 可选整数
源: IEnumerable<TSource>
选择器: Func<TSource, 可选整数>int? Sum(
IEnumerable<TSource> source,
Func<TSource, int?> selector)The total of a possibly missing number worked out from each element; nulls are skipped, and an empty sequence or all nulls gives 0, never null. Throws System.OverflowException when the total does not fit in an int.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 可选整数> | — | Gives the number for each element, or null to skip it. |
返回
| 结果 | 可选整数 |
重载 17/20
求和 -> 可选大整数
源: IEnumerable<TSource>
选择器: Func<TSource, 可选大整数>long? Sum(
IEnumerable<TSource> source,
Func<TSource, long?> selector)The total of a possibly missing number worked out from each element; nulls are skipped, and an empty sequence or all nulls gives 0, never null. Throws System.OverflowException when the total does not fit in a long.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 可选大整数> | — | Gives the number for each element, or null to skip it. |
返回
| 结果 | 可选大整数 |
重载 18/20
求和 -> 可选低精度数字
源: IEnumerable<TSource>
选择器: Func<TSource, 可选低精度数字>float? Sum(
IEnumerable<TSource> source,
Func<TSource, float?> selector)The total of a possibly missing number worked out from each element, added up in double precision and rounded to float at the end; nulls are skipped, and an empty sequence or all nulls gives 0, never null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 可选低精度数字> | — | Gives the number for each element, or null to skip it. |
返回
| 结果 | 可选低精度数字 |
重载 19/20
求和 -> 可选数字
源: IEnumerable<TSource>
选择器: Func<TSource, 可选数字>double? Sum(
IEnumerable<TSource> source,
Func<TSource, double?> selector)The total of a possibly missing number worked out from each element; nulls are skipped, and an empty sequence or all nulls gives 0, never null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 可选数字> | — | Gives the number for each element, or null to skip it. |
返回
| 结果 | 可选数字 |
重载 20/20
求和 -> 可选高精度数字
源: IEnumerable<TSource>
选择器: Func<TSource, 可选高精度数字>decimal? Sum(
IEnumerable<TSource> source,
Func<TSource, decimal?> selector)The exact decimal total of a possibly missing number worked out from each element; nulls are skipped, and an empty sequence or all nulls gives 0, never null. Throws System.OverflowException when the total exceeds the decimal range.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The elements to add up over. |
| 选择器 | Func<TSource, 可选高精度数字> | — | Gives the number for each element, or null to skip it. |
返回
| 结果 | 可选高精度数字 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
取前若干项
函数The first Count elements of the sequence: fewer when it is shorter, and none when the count is zero or less.
取前若干项 -> IEnumerable<TSource>
源: IEnumerable<TSource>
数量: 整数IEnumerable<TSource> Take(
IEnumerable<TSource> source,
int count)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to take from. |
| 数量 | 整数 | — | How many elements to take from the start. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
取末尾若干项
函数The last Count elements of the sequence: fewer when it is shorter, and none when the count is zero or less.
取末尾若干项 -> IEnumerable<TSource>
源: IEnumerable<TSource>
数量: 整数IEnumerable<TSource> TakeLast(
IEnumerable<TSource> source,
int count)参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to take from. |
| 数量 | 整数 | — | How many elements to take from the end. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
条件获取
函数重载 1/2
条件获取 -> IEnumerable<TSource>
源: IEnumerable<TSource>
条件: Func<TSource, 真否>IEnumerable<TSource> TakeWhile(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)Elements from the start for as long as Predicate answers true; it stops at the first element that fails, even if later elements would pass.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to take from. |
| 条件 | Func<TSource, 真否> | — | Answers true for each leading element to take. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
条件获取 -> IEnumerable<TSource>
源: IEnumerable<TSource>
条件: Func<TSource, 整数, 真否>IEnumerable<TSource> TakeWhile(
IEnumerable<TSource> source,
Func<TSource, int, bool> predicate)Elements from the start for as long as Predicate answers true; the test also receives each element's position.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to take from. |
| 条件 | Func<TSource, 整数, 真否> | — | Receives an element and its zero-based position, and answers true to take it. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
再按键排序
函数重载 1/2
再按键排序 -> IOrderedEnumerable<TSource>
源: IOrderedEnumerable<TSource>
键选择器: Func<TSource, TKey>IOrderedEnumerable<TSource> ThenBy(
IOrderedEnumerable<TSource> source,
Func<TSource, TKey> keySelector)Refines an existing sort: elements that tie on the earlier keys are put in ascending order of this further key, for example surname then first name. The input must come from an OrderBy, OrderByDescending, ThenBy or ThenByDescending node.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IOrderedEnumerable<TSource> | — | The already sorted sequence. |
| 键选择器 | Func<TSource, TKey> | — | Gives the tie-breaking key for each element. |
返回
| 结果 | IOrderedEnumerable<TSource> |
重载 2/2
再按键排序 -> IOrderedEnumerable<TSource>
源: IOrderedEnumerable<TSource>
键选择器: Func<TSource, TKey>
比较器: IComparer<TKey>IOrderedEnumerable<TSource> ThenBy(
IOrderedEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IComparer<TKey> comparer)Refines an existing sort: elements that tie on the earlier keys are put in ascending order of this further key, with Comparer deciding how keys are ordered.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IOrderedEnumerable<TSource> | — | The already sorted sequence. |
| 键选择器 | Func<TSource, TKey> | — | Gives the tie-breaking key for each element. |
| 比较器 | IComparer<TKey> | — | Decides which of two keys comes first; null uses the key type's default comparison. |
返回
| 结果 | IOrderedEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
再按键降序排序
函数重载 1/2
再按键降序排序 -> IOrderedEnumerable<TSource>
源: IOrderedEnumerable<TSource>
键选择器: Func<TSource, TKey>IOrderedEnumerable<TSource> ThenByDescending(
IOrderedEnumerable<TSource> source,
Func<TSource, TKey> keySelector)Refines an existing sort: elements that tie on the earlier keys are put in descending order of this further key. The input must come from an OrderBy, OrderByDescending, ThenBy or ThenByDescending node.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IOrderedEnumerable<TSource> | — | The already sorted sequence. |
| 键选择器 | Func<TSource, TKey> | — | Gives the tie-breaking key for each element. |
返回
| 结果 | IOrderedEnumerable<TSource> |
重载 2/2
再按键降序排序 -> IOrderedEnumerable<TSource>
源: IOrderedEnumerable<TSource>
键选择器: Func<TSource, TKey>
比较器: IComparer<TKey>IOrderedEnumerable<TSource> ThenByDescending(
IOrderedEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IComparer<TKey> comparer)Refines an existing sort: elements that tie on the earlier keys are put in descending order of this further key, with Comparer deciding how keys are ordered.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IOrderedEnumerable<TSource> | — | The already sorted sequence. |
| 键选择器 | Func<TSource, TKey> | — | Gives the tie-breaking key for each element. |
| 比较器 | IComparer<TKey> | — | Decides which of two keys comes first; null uses the key type's default comparison. |
返回
| 结果 | IOrderedEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
转为数组
函数Reads the whole sequence now and copies its elements into a new array, so later steps work on a fixed snapshot instead of re-running the query.
转为数组(源: IEnumerable<TSource>) -> TSource 数组
TSource[] ToArray(IEnumerable<TSource> source)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to copy. |
返回
| 结果 | TSource 数组 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
转为字典
函数重载 1/6
转为字典 -> TKey 到 TSource 的字典
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>Dictionary<TKey, TSource> ToDictionary(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)Reads the whole sequence into a new dictionary, keying each element by Key Selector. Throws System.ArgumentException when two elements give the same key and System.ArgumentNullException when a key is null; use ToLookup when keys can repeat.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to index. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element. |
返回
| 结果 | TKey 到 TSource 的字典 |
重载 2/6
转为字典 -> TKey 到 TSource 的字典
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
比较器: IEqualityComparer<TKey>Dictionary<TKey, TSource> ToDictionary(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> comparer)Reads the whole sequence into a new dictionary, keying each element by Key Selector, with Comparer deciding which keys are the same (the dictionary keeps using it for lookups). Throws System.ArgumentException when two elements give the same key and System.ArgumentNullException when a key is null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to index. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | TKey 到 TSource 的字典 |
重载 3/6
转为字典 -> TKey 到 TElement 的字典
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
元素选择器: Func<TSource, TElement>Dictionary<TKey, TElement> ToDictionary(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector)Reads the whole sequence into a new dictionary, with a key and a value worked out from each element, for example name to phone number. Throws System.ArgumentException when two elements give the same key and System.ArgumentNullException when a key is null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to index. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element. |
| 元素选择器 | Func<TSource, TElement> | — | Gives the value stored for each element. |
返回
| 结果 | TKey 到 TElement 的字典 |
重载 4/6
转为字典 -> TKey 到 TElement 的字典
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
元素选择器: Func<TSource, TElement>
比较器: IEqualityComparer<TKey>Dictionary<TKey, TElement> ToDictionary(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector,
IEqualityComparer<TKey> comparer)Reads the whole sequence into a new dictionary, with a key and a value worked out from each element and Comparer deciding which keys are the same. Throws System.ArgumentException when two elements give the same key and System.ArgumentNullException when a key is null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to index. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element. |
| 元素选择器 | Func<TSource, TElement> | — | Gives the value stored for each element. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | TKey 到 TElement 的字典 |
重载 5/6
转为字典(源: IEnumerable<KeyValuePair<TKey, TValue>>) -> TKey 到 TValue 的字典
Dictionary<TKey, TValue> ToDictionary(IEnumerable<KeyValuePair<TKey, TValue>> source)
Reads a sequence of key-value pairs into a new dictionary. Throws System.ArgumentException when a key appears twice and System.ArgumentNullException when a key is null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<KeyValuePair<TKey, TValue>> | — | The key-value pairs to store. |
返回
| 结果 | TKey 到 TValue 的字典 |
重载 6/6
转为字典 -> TKey 到 TValue 的字典
源: IEnumerable<KeyValuePair<TKey, TValue>>
比较器: IEqualityComparer<TKey>Dictionary<TKey, TValue> ToDictionary(
IEnumerable<KeyValuePair<TKey, TValue>> source,
IEqualityComparer<TKey> comparer)Reads a sequence of key-value pairs into a new dictionary, with Comparer deciding which keys are the same (the dictionary keeps using it for lookups). Throws System.ArgumentException when a key appears twice and System.ArgumentNullException when a key is null.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<KeyValuePair<TKey, TValue>> | — | The key-value pairs to store. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | TKey 到 TValue 的字典 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
转为集合
函数重载 1/2
转为集合(源: IEnumerable<TSource>) -> TSource 集合
HashSet<TSource> ToHashSet(IEnumerable<TSource> source)
Reads the whole sequence into a new set, dropping duplicates, for fast membership tests or further set operations.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to collect. |
返回
| 结果 | TSource 集合 |
重载 2/2
转为集合 -> TSource 集合
源: IEnumerable<TSource>
比较器: IEqualityComparer<TSource>HashSet<TSource> ToHashSet(
IEnumerable<TSource> source,
IEqualityComparer<TSource> comparer)Reads the whole sequence into a new set, with Comparer deciding which elements are duplicates (the set keeps using it for later membership tests).
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to collect. |
| 比较器 | IEqualityComparer<TSource> | — | Decides whether two elements are equal; null uses the default equality. |
返回
| 结果 | TSource 集合 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
转为列表
函数Reads the whole sequence now and copies its elements into a new list, so later steps work on a fixed snapshot that can also be added to.
转为列表(源: IEnumerable<TSource>) -> TSource 列表
List<TSource> ToList(IEnumerable<TSource> source)
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to copy. |
返回
| 结果 | TSource 列表 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
转为查找表
函数重载 1/4
转为查找表 -> ILookup<TKey, TSource>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>ILookup<TKey, TSource> ToLookup(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)Reads the whole sequence now into a lookup: a fixed, read-only grouping in which each key can have many elements, for example all orders per customer. Asking it for a key that has no elements gives an empty sequence rather than an error, and null keys are allowed.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to index. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element. |
返回
| 结果 | ILookup<TKey, TSource> |
重载 2/4
转为查找表 -> ILookup<TKey, TSource>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
比较器: IEqualityComparer<TKey>ILookup<TKey, TSource> ToLookup(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> comparer)Reads the whole sequence now into a lookup in which each key can have many elements, with Comparer deciding which keys are the same. A key with no elements gives an empty sequence.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to index. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | ILookup<TKey, TSource> |
重载 3/4
转为查找表 -> ILookup<TKey, TElement>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
元素选择器: Func<TSource, TElement>ILookup<TKey, TElement> ToLookup(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector)Reads the whole sequence now into a lookup in which each key can have many values, storing only the part of each element that Element Selector picks out. A key with no values gives an empty sequence.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to index. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element. |
| 元素选择器 | Func<TSource, TElement> | — | Gives the value stored for each element. |
返回
| 结果 | ILookup<TKey, TElement> |
重载 4/4
转为查找表 -> ILookup<TKey, TElement>
源: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
元素选择器: Func<TSource, TElement>
比较器: IEqualityComparer<TKey>ILookup<TKey, TElement> ToLookup(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector,
IEqualityComparer<TKey> comparer)Reads the whole sequence now into a lookup in which each key can have many values, storing only the part of each element that Element Selector picks out, with Comparer deciding which keys are the same.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to index. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key of each element. |
| 元素选择器 | Func<TSource, TElement> | — | Gives the value stored for each element. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | ILookup<TKey, TElement> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
并集
函数重载 1/2
并集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TSource>IEnumerable<TSource> Union(
IEnumerable<TSource> first,
IEnumerable<TSource> second)Every distinct element found in either sequence: those of First in order, then those of Second not already seen. Duplicates within either sequence are removed too.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence whose elements come first. |
| 第二个 | IEnumerable<TSource> | — | The sequence whose new elements follow. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
并集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TSource>
比较器: IEqualityComparer<TSource>IEnumerable<TSource> Union(
IEnumerable<TSource> first,
IEnumerable<TSource> second,
IEqualityComparer<TSource> comparer)Every distinct element found in either sequence, with Comparer deciding which elements are the same: those of First in order, then those of Second not already seen.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence whose elements come first. |
| 第二个 | IEnumerable<TSource> | — | The sequence whose new elements follow. |
| 比较器 | IEqualityComparer<TSource> | — | Decides whether two elements are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
按键求并集
函数重载 1/2
按键求并集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TSource>
键选择器: Func<TSource, TKey>IEnumerable<TSource> UnionBy(
IEnumerable<TSource> first,
IEnumerable<TSource> second,
Func<TSource, TKey> keySelector)Merges two sequences keeping one element per key, for example one entry per ID across two lists; the first element seen with each key is kept, those of First before those of Second.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence whose elements come first. |
| 第二个 | IEnumerable<TSource> | — | The sequence whose elements with new keys follow. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides whether two elements count as the same. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
按键求并集 -> IEnumerable<TSource>
第一个: IEnumerable<TSource>
第二个: IEnumerable<TSource>
键选择器: Func<TSource, TKey>
比较器: IEqualityComparer<TKey>IEnumerable<TSource> UnionBy(
IEnumerable<TSource> first,
IEnumerable<TSource> second,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> comparer)Merges two sequences keeping one element per key, with Comparer deciding which keys are the same; the first element seen with each key is kept.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 第一个 | IEnumerable<TSource> | — | The sequence whose elements come first. |
| 第二个 | IEnumerable<TSource> | — | The sequence whose elements with new keys follow. |
| 键选择器 | Func<TSource, TKey> | — | Gives the key that decides whether two elements count as the same. |
| 比较器 | IEqualityComparer<TKey> | — | Decides whether two keys are equal; null uses the default equality. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库
筛选
函数重载 1/2
筛选 -> IEnumerable<TSource>
源: IEnumerable<TSource>
条件: Func<TSource, 真否>IEnumerable<TSource> Where(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)Filters a sequence: only the elements for which Predicate answers true, in their original order.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to filter. |
| 条件 | Func<TSource, 真否> | — | Answers true for each element to keep. |
返回
| 结果 | IEnumerable<TSource> |
重载 2/2
筛选 -> IEnumerable<TSource>
源: IEnumerable<TSource>
条件: Func<TSource, 整数, 真否>IEnumerable<TSource> Where(
IEnumerable<TSource> source,
Func<TSource, int, bool> predicate)Filters a sequence with a test that can also see each element's position, for example to keep every other element.
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| 源 | IEnumerable<TSource> | — | The sequence to filter. |
| 条件 | Func<TSource, 整数, 真否> | — | Receives an element and its zero-based position in Source, and answers true to keep it. |
返回
| 结果 | IEnumerable<TSource> |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 可枚举序列操作
- 所属包
- 标准库