可列舉序列操作
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> |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 可列舉序列操作
- 所屬包
- 標準庫