元编程参考文档

集合操作

19 个节点

本页内容 19

添加

函数

此节点没有文档说明。

签名
添加(集合: T 集合, 项: T) -> 真否
bool Add(HashSet<T> set, T item)

参数

名称类型默认值说明
集合T 集合—
项T—

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

清空

函数

Removes every element from the set, in place; the set itself stays usable and keeps its equality rule.

签名
清空(集合: T 集合)
void Clear(HashSet<T> set)

参数

名称类型默认值说明
集合T 集合—The set to empty.
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

复制集合

函数

An independent copy of the set with the same elements and the same equality rule, so that changing one does not change the other. The elements themselves are shared, not copied.

签名
复制集合(集合: T 集合) -> T 集合
HashSet<T> Clone(HashSet<T> set)

参数

名称类型默认值说明
集合T 集合—The set to copy.

返回

结果T 集合
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

比较器

函数

The equality rule the set uses to decide which elements are the same, for creating another set that behaves alike.

签名
比较器(集合: T 集合) -> IEqualityComparer<T>
IEqualityComparer<T> Comparer(HashSet<T> set)

参数

名称类型默认值说明
集合T 集合—The set to inspect.

返回

结果IEqualityComparer<T>
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

包含

函数

Whether the set holds an element equal to Item, by the set's own equality rule; this is a fast lookup, however large the set.

签名
包含(集合: T 集合, 项: T) -> 真否
bool Contains(HashSet<T> set, T item)

参数

名称类型默认值说明
集合T 集合—The set to search.
项T—The element to look for.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

项数

函数

How many elements the set holds.

签名
项数(集合: T 集合) -> 整数
int Count(HashSet<T> set)

参数

名称类型默认值说明
集合T 集合—The set to measure.

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

创建集合

函数

重载 1/5

签名
创建集合() -> T 集合
HashSet<T> Create()

A new, empty set that compares its elements by their default equality.

返回

结果T 集合

重载 2/5

签名
创建集合(容量: 整数) -> T 集合
HashSet<T> Create(int capacity)

A new, empty set with room for Capacity elements before it has to grow, for when the final size is known in advance. Throws System.ArgumentOutOfRangeException when Capacity is negative.

参数

名称类型默认值说明
容量整数—How many elements to make room for.

返回

结果T 集合

重载 3/5

签名
创建集合(比较器: IEqualityComparer<T>) -> T 集合
HashSet<T> Create(IEqualityComparer<T> comparer)

A new, empty set that uses Comparer to decide which elements are the same, for example text compared without regard to case.

参数

名称类型默认值说明
比较器IEqualityComparer<T>—Decides whether two elements are equal; null uses the default equality.

返回

结果T 集合

重载 4/5

签名
创建集合(源: IEnumerable<T>) -> T 集合
HashSet<T> Create(IEnumerable<T> source)

A new set holding the elements of a sequence, with duplicates dropped, compared by their default equality.

参数

名称类型默认值说明
源IEnumerable<T>—The elements to put in the set.

返回

结果T 集合

重载 5/5

签名
创建集合 -> T 集合
    源: IEnumerable<T>
    比较器: IEqualityComparer<T>
HashSet<T> Create(
    IEnumerable<T> source,
    IEqualityComparer<T> comparer)

A new set holding the elements of a sequence, with Comparer deciding which ones are duplicates; the set keeps using it afterwards.

参数

名称类型默认值说明
源IEnumerable<T>—The elements to put in the set.
比较器IEqualityComparer<T>—Decides whether two elements are equal; null uses the default equality.

返回

结果T 集合
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

差集

函数

The first operand's elements minus the second's, in a new set; both operands untouched.

签名
差集(集合: T 集合, 另一个: IEnumerable<T>) -> T 集合
HashSet<T> Except(HashSet<T> set, IEnumerable<T> other)

参数

名称类型默认值说明
集合T 集合—
另一个IEnumerable<T>—

返回

结果T 集合
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

交集

函数

Only the elements both operands have, in a new set; both operands untouched.

签名
交集(集合: T 集合, 另一个: IEnumerable<T>) -> T 集合
HashSet<T> Intersect(HashSet<T> set, IEnumerable<T> other)

参数

名称类型默认值说明
集合T 集合—
另一个IEnumerable<T>—

返回

结果T 集合
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

为空

函数

Whether the set holds no elements.

签名
为空(集合: T 集合) -> 真否
bool IsEmpty(HashSet<T> set)

参数

名称类型默认值说明
集合T 集合—The set to test.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

是否为子集

函数

Whether every element of Set is also in Other, by the set's equality rule. An empty set is a subset of anything, and a set is a subset of itself.

签名
是否为子集(集合: T 集合, 另一个: IEnumerable<T>) -> 真否
bool IsSubsetOf(HashSet<T> set, IEnumerable<T> other)

参数

名称类型默认值说明
集合T 集合—The set that should be contained.
另一个IEnumerable<T>—The elements it should be contained in; duplicates and order do not matter.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

是否为超集

函数

Whether every element of Other is also in Set, by the set's equality rule. Any set is a superset of an empty sequence.

签名
是否为超集(集合: T 集合, 另一个: IEnumerable<T>) -> 真否
bool IsSupersetOf(HashSet<T> set, IEnumerable<T> other)

参数

名称类型默认值说明
集合T 集合—The set that should contain the elements.
另一个IEnumerable<T>—The elements it should contain; duplicates and order do not matter.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

是否有交集

函数

Whether the set and the other elements have at least one element in common, by the set's equality rule; false when either is empty.

签名
是否有交集(集合: T 集合, 另一个: IEnumerable<T>) -> 真否
bool Overlaps(HashSet<T> set, IEnumerable<T> other)

参数

名称类型默认值说明
集合T 集合—The set to test.
另一个IEnumerable<T>—The elements to look for in the set.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

移除

函数

此节点没有文档说明。

签名
移除(集合: T 集合, 项: T) -> 真否
bool Remove(HashSet<T> set, T item)

参数

名称类型默认值说明
集合T 集合—
项T—

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

集合相等

函数

Whether the set and the other elements hold exactly the same elements, by the set's equality rule, ignoring order and any duplicates in Other.

签名
集合相等(集合: T 集合, 另一个: IEnumerable<T>) -> 真否
bool SetEquals(HashSet<T> set, IEnumerable<T> other)

参数

名称类型默认值说明
集合T 集合—The set to compare.
另一个IEnumerable<T>—The elements to compare it with.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

对称差集

函数

The elements in exactly one of the two operands, in a new set; both operands untouched.

签名
对称差集(集合: T 集合, 另一个: IEnumerable<T>) -> T 集合
HashSet<T> SymmetricExcept(HashSet<T> set, IEnumerable<T> other)

参数

名称类型默认值说明
集合T 集合—
另一个IEnumerable<T>—

返回

结果T 集合
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

转为数组

函数

Copies the set's elements into a new array, for when an indexed or ordered collection is needed. The order is whatever order the set happens to hold them in, which is not guaranteed to be insertion order.

签名
转为数组(集合: T 集合) -> T 数组
T[] ToArray(HashSet<T> set)

参数

名称类型默认值说明
集合T 集合—The set to copy.

返回

结果T 数组
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

转为列表

函数

Copies the set's elements into a new list, for when an indexed collection that can hold duplicates is needed. The order is whatever order the set happens to hold them in, which is not guaranteed to be insertion order.

签名
转为列表(集合: T 集合) -> T 列表
List<T> ToList(HashSet<T> set)

参数

名称类型默认值说明
集合T 集合—The set to copy.

返回

结果T 列表
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库

并集

函数

Every element in either operand, in a new set; both operands untouched.

签名
并集(集合: T 集合, 另一个: IEnumerable<T>) -> T 集合
HashSet<T> Union(HashSet<T> set, IEnumerable<T> other)

参数

名称类型默认值说明
集合T 集合—
另一个IEnumerable<T>—

返回

结果T 集合
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
集合操作
所属包
标准库