列表操作
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 |
- 所属发行版
- 元编程(教育版)元编程(专业版)
- 可用的图种类
- 数据流 函数 事件 例程 蓝图 状态机状态
- 声明于
- 列表操作
- 所属包
- 标准库