列表操作
42 個節點
本頁內容 42
新增
函數Appends an element to the end of the list.
新增(列表: T 列表, 項: T)
void Add(List<T> list, T item)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to extend; null throws System.ArgumentNullException. |
| 項 | T | — | The element to append; null is allowed for reference types. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
新增多項
函數Appends every element of a sequence to the end of the list, keeping their order.
新增多項(列表: T 列表, 多項: IEnumerable<T>)
void AddRange(List<T> list, IEnumerable<T> items)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to extend; null throws System.ArgumentNullException. |
| 多項 | IEnumerable<T> | — | The elements to append; null throws System.ArgumentNullException. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
作為只讀列表
函數A read-only view of the list, for handing its contents on without letting the receiver change them.
作為只讀列表(列表: T 列表) -> ReadOnlyCollection<T>
ReadOnlyCollection<T> AsReadOnly(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to wrap; null throws System.ArgumentNullException. |
返回
| 結果 | ReadOnlyCollection<T> |
備註
The view is not a copy: changes made to the list afterwards show through it.
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
二分查詢
函數過載 1/3
二分查詢(列表: T 列表, 項: T) -> 整數
int BinarySearch(List<T> list, T item)
Finds a value in a list that is already sorted in ascending order, much faster than a front-to-back search on a long list.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The sorted list to search; null throws System.ArgumentNullException. |
| 項 | T | — | The value to look for. |
返回
| 結果 | 整數 |
備註
The result is only meaningful if the list is sorted by the same ordering; if several elements equal the value, any one of their positions may be returned. Elements that are not comparable throw System.InvalidOperationException.
過載 2/3
二分查詢(列表: T 列表, 項: T, 比較器: IComparer<T>) -> 整數
int BinarySearch(List<T> list, T item, IComparer<T> comparer)
Finds a value in a list that is already sorted by the given comparer, much faster than a front-to-back search on a long list.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The sorted list to search; null throws System.ArgumentNullException. |
| 項 | T | — | The value to look for. |
| 比較器 | IComparer<T> | — | The ordering the list is sorted by; null uses the elements' default ordering. |
返回
| 結果 | 整數 |
備註
The result is only meaningful if the list is sorted by the same comparer; if several elements equal the value, any one of their positions may be returned.
過載 3/3
二分查詢 -> 整數
列表: T 列表
索引: 整數
數量: 整數
項: T
比較器: IComparer<T>int BinarySearch(
List<T> list,
int index,
int count,
T item,
IComparer<T> comparer)Finds a value within a section of the list, where that section is already sorted by the given comparer.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position where the section starts; negative throws System.ArgumentOutOfRangeException. |
| 數量 | 整數 | — | How many elements the section covers; negative throws System.ArgumentOutOfRangeException, and a section past the end throws System.ArgumentException. |
| 項 | T | — | The value to look for. |
| 比較器 | IComparer<T> | — | The ordering the section is sorted by; null uses the elements' default ordering. |
返回
| 結果 | 整數 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
容量
函數How many elements the list can hold before it has to grow its storage; always at least its count.
容量(列表: T 列表) -> 整數
int Capacity(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to inspect; null throws System.ArgumentNullException. |
返回
| 結果 | 整數 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
清空
函數Removes every element, leaving an empty list; its reserved capacity is kept.
清空(列表: T 列表)
void Clear(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to empty; null throws System.ArgumentNullException. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
複製列表
函數A new list with the same elements in the same order, so the copy can be changed without affecting the original.
複製列表(列表: T 列表) -> T 列表
List<T> Clone(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to copy; null throws System.ArgumentNullException. |
返回
| 結果 | T 列表 |
備註
The copy is shallow: for elements that are objects, both lists refer to the same objects.
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
包含
函數Whether the list holds an element equal to the given value.
包含(列表: T 列表, 項: T) -> 真否
bool Contains(List<T> list, T item)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 項 | T | — | The value to look for, compared by equality. |
返回
| 結果 | 真否 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
全部轉換
函數A new list made by passing each element through a converter, for turning a list of one type into another, such as numbers into labels.
全部轉換 -> TOut 列表
列表: TIn 列表
轉換器: Converter<TIn, TOut>List<TOut> ConvertAll(
List<TIn> list,
Converter<TIn, TOut> converter)參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | TIn 列表 | — | The list to convert; it is left unchanged, and null throws System.ArgumentNullException. |
| 轉換器 | Converter<TIn, TOut> | — | The function applied to each element; null throws System.ArgumentNullException. |
返回
| 結果 | TOut 列表 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
複製到陣列
函數過載 1/3
複製到陣列(列表: T 列表, 陣列: T 陣列)
void CopyTo(List<T> list, T[] array)
Copies every element of the list into an existing array, starting at the array's first slot.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to copy from; null throws System.ArgumentNullException. |
| 陣列 | T 陣列 | — | The array to copy into; null throws System.ArgumentNullException, and one shorter than the list throws System.ArgumentException. |
過載 2/3
複製到陣列(列表: T 列表, 陣列: T 陣列, 陣列索引: 整數)
void CopyTo(List<T> list, T[] array, int arrayIndex)
Copies every element of the list into an existing array, starting at a given slot of the array.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to copy from; null throws System.ArgumentNullException. |
| 陣列 | T 陣列 | — | The array to copy into; null throws System.ArgumentNullException. |
| 陣列索引 | 整數 | — | The array position where the first element lands; too little room after it for the whole list throws System.ArgumentException. |
過載 3/3
複製到陣列
列表: T 列表
索引: 整數
陣列: T 陣列
陣列索引: 整數
數量: 整數void CopyTo(
List<T> list,
int index,
T[] array,
int arrayIndex,
int count)Copies a run of the list's elements into an existing array at a given slot.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to copy from; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based list position of the first element to copy. |
| 陣列 | T 陣列 | — | The array to copy into; null throws System.ArgumentNullException. |
| 陣列索引 | 整數 | — | The array position where the first copied element lands. |
| 數量 | 整數 | — | How many elements to copy; a negative position or count throws System.ArgumentOutOfRangeException, and a run past the end of the list or of the array throws System.ArgumentException. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
項數
函數How many elements the list currently holds.
項數(列表: T 列表) -> 整數
int Count(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to count; null throws System.ArgumentNullException. |
返回
| 結果 | 整數 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
建立列表
函數過載 1/3
建立列表() -> T 列表
List<T> Create()
A new, empty list that you can add elements to.
返回
| 結果 | T 列表 |
過載 2/3
建立列表(容量: 整數) -> T 列表
List<T> Create(int capacity)
A new, empty list with room reserved for a number of elements, which avoids repeated regrowth when you know roughly how many you will add.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 容量 | 整數 | — | How many elements to reserve room for; this is not the list's length, which starts at 0. Negative throws System.ArgumentOutOfRangeException. |
返回
| 結果 | T 列表 |
過載 3/3
建立列表(來源: IEnumerable<T>) -> T 列表
List<T> Create(IEnumerable<T> source)
A new list holding the elements of an existing sequence, such as an array, in the same order.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 來源 | IEnumerable<T> | — | The elements to copy into the list; null throws System.ArgumentNullException. |
返回
| 結果 | T 列表 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
確保容量
函數Makes sure the list has room for at least the given number of elements, growing its storage if it is smaller; the elements themselves are not changed.
確保容量(列表: T 列表, 容量: 整數) -> 整數
int EnsureCapacity(List<T> list, int capacity)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to prepare; null throws System.ArgumentNullException. |
| 容量 | 整數 | — | The minimum number of elements to have room for; negative throws System.ArgumentOutOfRangeException. |
返回
| 結果 | 整數 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
存在滿足條件的項
函數Whether at least one element passes a test, for questions such as "is any value negative?".
存在滿足條件的項(列表: T 列表, 條件: Predicate<T>) -> 真否
bool Exists(List<T> list, Predicate<T> match)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to check; null throws System.ArgumentNullException. |
| 條件 | Predicate<T> | — | The test applied to each element; null throws System.ArgumentNullException. |
返回
| 結果 | 真否 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
查詢
函數The first element, from the front, that passes a test.
查詢(列表: T 列表, 條件: Predicate<T>) -> T
T Find(List<T> list, Predicate<T> match)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 條件 | Predicate<T> | — | The test applied to each element; null throws System.ArgumentNullException. |
返回
| Result | T |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
查詢索引
函數過載 1/3
查詢索引(列表: T 列表, 條件: Predicate<T>) -> 整數
int FindIndex(List<T> list, Predicate<T> match)
The position of the first element that passes a test, searching from the front.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 條件 | Predicate<T> | — | The test applied to each element; null throws System.ArgumentNullException. |
返回
| 結果 | 整數 |
過載 2/3
查詢索引 -> 整數
列表: T 列表
起始索引: 整數
條件: Predicate<T>int FindIndex(List<T> list, int startIndex, Predicate<T> match)
The position of the first element passing a test, searching forwards from a given index to the end.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 起始索引 | 整數 | — | The zero-based index where the search starts; below 0 or above the count throws System.ArgumentOutOfRangeException. |
| 條件 | Predicate<T> | — | The test applied to each element; null throws System.ArgumentNullException. |
返回
| 結果 | 整數 |
過載 3/3
查詢索引 -> 整數
列表: T 列表
起始索引: 整數
數量: 整數
條件: Predicate<T>int FindIndex(
List<T> list,
int startIndex,
int count,
Predicate<T> match)The position of the first element passing a test within a section of the list, searching forwards.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 起始索引 | 整數 | — | The zero-based index where the search starts. |
| 數量 | 整數 | — | How many elements to examine; a section outside the list throws System.ArgumentOutOfRangeException. |
| 條件 | Predicate<T> | — | The test applied to each element; null throws System.ArgumentNullException. |
返回
| 結果 | 整數 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
查詢最後一個
函數The last element, searching from the back, that passes a test.
查詢最後一個(列表: T 列表, 條件: Predicate<T>) -> T
T FindLast(List<T> list, Predicate<T> match)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 條件 | Predicate<T> | — | The test applied to each element; null throws System.ArgumentNullException. |
返回
| Result | T |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
第一項
函數The first element of the list.
第一項(列表: T 列表) -> T
T First(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to read; null throws System.ArgumentNullException. |
返回
| Result | T |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
逐項執行
函數Runs an action once for each element, front to back, for side effects such as printing or accumulating.
逐項執行(列表: T 列表, 操作: Action<T>)
void ForEach(List<T> list, Action<T> action)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to walk; null throws System.ArgumentNullException. |
| 操作 | Action<T> | — | The action run on each element; null throws System.ArgumentNullException. |
備註
The action must not change the same list (adding, removing or replacing elements); doing so throws System.InvalidOperationException.
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
取得項
函數The element at a position in the list, counting from 0.
取得項(列表: T 列表, 索引: 整數) -> T
T Get(List<T> list, int index)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to read; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position; below 0 or not less than the count throws System.ArgumentOutOfRangeException. |
返回
| Result | T |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
取得範圍
函數A new list holding a run of consecutive elements copied from this one.
取得範圍(列表: T 列表, 索引: 整數, 數量: 整數) -> T 列表
List<T> GetRange(List<T> list, int index, int count)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to copy from; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position of the first element to copy; negative throws System.ArgumentOutOfRangeException. |
| 數量 | 整數 | — | How many elements to copy; negative throws System.ArgumentOutOfRangeException, and a run past the end throws System.ArgumentException. |
返回
| 結果 | T 列表 |
備註
The copy is shallow, and changing the new list does not change the original.
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
項的索引
函數過載 1/3
項的索引(列表: T 列表, 項: T) -> 整數
int IndexOf(List<T> list, T item)
The position of the first element equal to the given value, searching from the front.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 項 | T | — | The value to look for, compared by equality. |
返回
| 結果 | 整數 |
過載 2/3
項的索引(列表: T 列表, 項: T, 索引: 整數) -> 整數
int IndexOf(List<T> list, T item, int index)
The position of the first element equal to the given value, searching forwards from a given index to the end.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 項 | T | — | The value to look for, compared by equality. |
| 索引 | 整數 | — | The zero-based index where the search starts; below 0 or above the count throws System.ArgumentOutOfRangeException. |
返回
| 結果 | 整數 |
過載 3/3
項的索引(列表: T 列表, 項: T, 索引: 整數, 數量: 整數) -> 整數
int IndexOf(List<T> list, T item, int index, int count)
The position of the first element equal to the given value within a section of the list, searching forwards.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 項 | T | — | The value to look for, compared by equality. |
| 索引 | 整數 | — | The zero-based index where the search starts. |
| 數量 | 整數 | — | How many elements to examine; a section outside the list throws System.ArgumentOutOfRangeException. |
返回
| 結果 | 整數 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
插入
函數Inserts an element at a position, moving the element there and everything after it one place along.
插入(列表: T 列表, 索引: 整數, 項: T)
void Insert(List<T> list, int index, T item)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to change; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position the new element takes; equal to the count appends it, and below 0 or above the count throws System.ArgumentOutOfRangeException. |
| 項 | T | — | The element to insert. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
插入多項
函數Inserts every element of a sequence at a position, keeping their order and moving the existing elements from there onwards along to make room.
插入多項(列表: T 列表, 索引: 整數, 多項: IEnumerable<T>)
void InsertRange(List<T> list, int index, IEnumerable<T> items)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to change; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position the first inserted element takes; equal to the count appends, and below 0 or above the count throws System.ArgumentOutOfRangeException. |
| 多項 | IEnumerable<T> | — | The elements to insert; null throws System.ArgumentNullException. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
為空
函數Whether the list has no elements.
為空(列表: T 列表) -> 真否
bool IsEmpty(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to check; null throws System.ArgumentNullException. |
返回
| 結果 | 真否 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
最後一項
函數The last element of the list.
最後一項(列表: T 列表) -> T
T Last(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to read; null throws System.ArgumentNullException. |
返回
| Result | T |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
項的最後索引
函數The position of the last element equal to the given value, searching from the back.
項的最後索引(列表: T 列表, 項: T) -> 整數
int LastIndexOf(List<T> list, T item)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to search; null throws System.ArgumentNullException. |
| 項 | T | — | The value to look for, compared by equality. |
返回
| 結果 | 整數 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
移除
函數Removes the first element equal to the given value, if there is one; later duplicates stay.
移除(列表: T 列表, 項: T) -> 真否
bool Remove(List<T> list, T item)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to change; null throws System.ArgumentNullException. |
| 項 | T | — | The value to remove, compared by equality. |
返回
| 結果 | 真否 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
移除所有滿足條件的項
函數Removes every element that passes a test, for filtering a list in place.
移除所有滿足條件的項(列表: T 列表, 條件: Predicate<T>) -> 整數
int RemoveAll(List<T> list, Predicate<T> match)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to change; null throws System.ArgumentNullException. |
| 條件 | Predicate<T> | — | The test applied to each element; matching elements are removed. Null throws System.ArgumentNullException. |
返回
| 結果 | 整數 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
移除指定位置的項
函數Removes the element at a position, moving everything after it one place back.
移除指定位置的項(列表: T 列表, 索引: 整數)
void RemoveAt(List<T> list, int index)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to change; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position to remove; below 0 or not less than the count throws System.ArgumentOutOfRangeException. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
移除範圍
函數Removes a run of consecutive elements, moving everything after them back to close the gap.
移除範圍(列表: T 列表, 索引: 整數, 數量: 整數)
void RemoveRange(List<T> list, int index, int count)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to change; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position of the first element to remove; negative throws System.ArgumentOutOfRangeException. |
| 數量 | 整數 | — | How many elements to remove; negative throws System.ArgumentOutOfRangeException, and a run past the end throws System.ArgumentException. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
反轉
函數過載 1/2
反轉(列表: T 列表)
void Reverse(List<T> list)
Reverses the order of all elements in place, so the last becomes first.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to reverse; null throws System.ArgumentNullException. |
過載 2/2
反轉(列表: T 列表, 索引: 整數, 數量: 整數)
void Reverse(List<T> list, int index, int count)
Reverses the order of a run of elements in place, leaving the rest of the list as it was.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to change; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position of the first element of the run; negative throws System.ArgumentOutOfRangeException. |
| 數量 | 整數 | — | How many elements the run covers; negative throws System.ArgumentOutOfRangeException, and a run past the end throws System.ArgumentException. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
設定項
函數Replaces the element at a position in the list with a new value.
設定項(列表: T 列表, 索引: 整數, 值: T)
void Set(List<T> list, int index, T value)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to change; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position to overwrite; below 0 or not less than the count throws System.ArgumentOutOfRangeException (use Add or Insert to extend the list). |
| 值 | T | — | The value to store. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
設定容量
函數Sets exactly how many elements the list has room for, to reserve space ahead of time or release unused space.
設定容量(列表: T 列表, 容量: 整數)
void SetCapacity(List<T> list, int capacity)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to change; null throws System.ArgumentNullException. |
| 容量 | 整數 | — | The new capacity; it cannot be negative or less than the list's count, either of which throws System.ArgumentOutOfRangeException. |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
切片
函數A new list holding a run of consecutive elements copied from this one; the same as Get Range, named for those used to slicing.
切片(列表: T 列表, 起始: 整數, 長度: 整數) -> T 列表
List<T> Slice(List<T> list, int start, int length)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to copy from; null throws System.ArgumentNullException. |
| 起始 | 整數 | — | The zero-based position of the first element to copy; negative throws System.ArgumentOutOfRangeException. |
| 長度 | 整數 | — | How many elements to copy (not an end position); negative throws System.ArgumentOutOfRangeException, and a run past the end throws System.ArgumentException. |
返回
| 結果 | T 列表 |
備註
The copy is shallow, and changing the new list does not change the original.
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
排序
函數過載 1/4
排序(列表: T 列表)
void Sort(List<T> list)
Sorts the list in place in ascending order: numbers smallest first, text alphabetically.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to sort; null throws System.ArgumentNullException. |
備註
The sort is not stable: elements that compare equal may change order. Elements that are not comparable throw System.InvalidOperationException.
過載 2/4
排序(列表: T 列表, 比較器: IComparer<T>)
void Sort(List<T> list, IComparer<T> comparer)
Sorts the list in place using the given comparer.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to sort; null throws System.ArgumentNullException. |
| 比較器 | IComparer<T> | — | The ordering to sort by; null uses the elements' default ordering, which throws System.InvalidOperationException if the elements are not comparable. |
備註
The sort is not stable: elements that compare equal may change order.
過載 3/4
排序(列表: T 列表, 索引: 整數, 數量: 整數, 比較器: IComparer<T>)
void Sort(
List<T> list,
int index,
int count,
IComparer<T> comparer)Sorts a run of elements in place using the given comparer, leaving the rest of the list as it was.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to sort; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position of the first element of the run; negative throws System.ArgumentOutOfRangeException. |
| 數量 | 整數 | — | How many elements the run covers; negative throws System.ArgumentOutOfRangeException, and a run past the end throws System.ArgumentException. |
| 比較器 | IComparer<T> | — | The ordering to sort by; null uses the elements' default ordering. |
備註
The sort is not stable.
過載 4/4
排序(列表: T 列表, 比較方式: Comparison<T>)
void Sort(List<T> list, Comparison<T> comparison)
Sorts the list in place using a comparison function, for orderings such as by length or descending.
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to sort; null throws System.ArgumentNullException. |
| 比較方式 | Comparison<T> | — | The function that orders two elements; null throws System.ArgumentNullException. |
備註
The comparison returns a negative number when the first argument comes first, 0 when they are equal and a positive number when the second comes first. The sort is not stable.
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
轉為陣列
函數The list's elements copied into a new array, in the same order, for nodes that take an array.
轉為陣列(列表: T 列表) -> T 陣列
T[] ToArray(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to copy; null throws System.ArgumentNullException. |
返回
| 結果 | T 陣列 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
釋放多餘容量
函數Shrinks the list's reserved storage to fit its elements, to give memory back once a list has finished growing.
釋放多餘容量(列表: T 列表)
void TrimExcess(List<T> list)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to trim; null throws System.ArgumentNullException. |
備註
Nothing happens if the list already uses more than about 90% of its capacity, since reallocating would cost more than it saves.
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
全部滿足條件
函數Whether every element passes a test, for questions such as "are all values positive?".
全部滿足條件(列表: T 列表, 條件: Predicate<T>) -> 真否
bool TrueForAll(List<T> list, Predicate<T> match)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to check; null throws System.ArgumentNullException. |
| 條件 | Predicate<T> | — | The test applied to each element; null throws System.ArgumentNullException. |
返回
| 結果 | 真否 |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
嘗試取得第一項
函數Reads the first element if the list has one, without throwing on an empty list.
嘗試取得第一項(列表: T 列表) -> (結果: 真否, 值: T)
bool TryFirst(List<T> list, out T value)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to read; null throws System.ArgumentNullException. |
返回
| 結果 | 真否 |
| 值 | T |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
嘗試取得項
函數Reads the element at a position if there is one, without throwing when the position is out of range.
嘗試取得項(列表: T 列表, 索引: 整數) -> (結果: 真否, 值: T)
bool TryGet(List<T> list, int index, out T value)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to read; null throws System.ArgumentNullException. |
| 索引 | 整數 | — | The zero-based position to read. |
返回
| 結果 | 真否 |
| 值 | T |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫
嘗試取得最後一項
函數Reads the last element if the list has one, without throwing on an empty list.
嘗試取得最後一項(列表: T 列表) -> (結果: 真否, 值: T)
bool TryLast(List<T> list, out T value)
參數
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
| 列表 | T 列表 | — | The list to read; null throws System.ArgumentNullException. |
返回
| 結果 | 真否 |
| 值 | T |
- 所屬發行版
- 元編程(教育版)元編程(專業版)
- 可用的圖種類
- 資料流 函數 事件 例程 藍圖 狀態機狀態
- 宣告於
- 列表操作
- 所屬包
- 標準庫