元编程参考文档

元组操作

16 个节点

本页内容 16

比较

函数

Orders two tuples of the same type element by element: the first position where they differ decides, as in sorting by several columns.

签名
比较(左侧: TTuple, 右侧: TTuple) -> 整数
int Compare(TTuple left, TTuple right)

参数

名称类型默认值说明
左侧TTuple—The first tuple.
右侧TTuple—The second tuple.

返回

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

比较对象

函数

Orders two values when you only have them as plain objects, using the left value's own comparison; null sorts before everything else.

签名
比较对象(左侧: 任意, 右侧: 任意) -> 整数
int CompareObjects(object left, object right)

参数

名称类型默认值说明
左侧任意—The first value; it must be comparable (as tuples, numbers and text are), or System.ArgumentException is thrown. Null sorts first.
右侧任意—The second value; it must be of a type the left value can compare against, or the left value's comparison throws (for a tuple, System.ArgumentException).

返回

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

创建元组

函数

重载 1/9

签名
创建元组() -> ValueTuple
ValueTuple Create()

Makes the empty tuple, which holds no elements; it is the tuple form of "nothing", and every empty tuple equals every other.

返回

结果ValueTuple

重载 2/9

签名
创建元组(项 1: T1) -> (T1)
ValueTuple<T1> Create(T1 item1)

Makes a tuple holding one element.

参数

名称类型默认值说明
项 1T1—The element.

返回

结果(T1)

重载 3/9

签名
创建元组(项 1: T1, 项 2: T2) -> (T1, T2)
(T1, T2) Create(T1 item1, T2 item2)

Makes a pair: a tuple holding two elements, which may be of different types, for passing two related values along one wire.

参数

名称类型默认值说明
项 1T1—The first element.
项 2T2—The second element.

返回

结果(T1, T2)

重载 4/9

签名
创建元组(项 1: T1, 项 2: T2, 项 3: T3) -> (T1, T2, T3)
(T1, T2, T3) Create(T1 item1, T2 item2, T3 item3)

Makes a tuple holding three elements, which may be of different types.

参数

名称类型默认值说明
项 1T1—The first element.
项 2T2—The second element.
项 3T3—The third element.

返回

结果(T1, T2, T3)

重载 5/9

签名
创建元组 -> (T1, T2, T3, T4)
    项 1: T1
    项 2: T2
    项 3: T3
    项 4: T4
(T1, T2, T3, T4) Create(T1 item1, T2 item2, T3 item3, T4 item4)

Makes a tuple holding four elements, which may be of different types.

参数

名称类型默认值说明
项 1T1—The first element.
项 2T2—The second element.
项 3T3—The third element.
项 4T4—The fourth element.

返回

结果(T1, T2, T3, T4)

重载 6/9

签名
创建元组 -> (T1, T2, T3, T4, T5)
    项 1: T1
    项 2: T2
    项 3: T3
    项 4: T4
    项 5: T5
(T1, T2, T3, T4, T5) Create(
    T1 item1,
    T2 item2,
    T3 item3,
    T4 item4,
    T5 item5)

Makes a tuple holding five elements, which may be of different types.

参数

名称类型默认值说明
项 1T1—The first element.
项 2T2—The second element.
项 3T3—The third element.
项 4T4—The fourth element.
项 5T5—The fifth element.

返回

结果(T1, T2, T3, T4, T5)

重载 7/9

签名
创建元组 -> (T1, T2, T3, T4, T5, T6)
    项 1: T1
    项 2: T2
    项 3: T3
    项 4: T4
    项 5: T5
    项 6: T6
(T1, T2, T3, T4, T5, T6) Create(
    T1 item1,
    T2 item2,
    T3 item3,
    T4 item4,
    T5 item5,
    T6 item6)

Makes a tuple holding six elements, which may be of different types.

参数

名称类型默认值说明
项 1T1—The first element.
项 2T2—The second element.
项 3T3—The third element.
项 4T4—The fourth element.
项 5T5—The fifth element.
项 6T6—The sixth element.

返回

结果(T1, T2, T3, T4, T5, T6)

重载 8/9

签名
创建元组 -> (T1, T2, T3, T4, T5, T6, T7)
    项 1: T1
    项 2: T2
    项 3: T3
    项 4: T4
    项 5: T5
    项 6: T6
    项 7: T7
(T1, T2, T3, T4, T5, T6, T7) Create(
    T1 item1,
    T2 item2,
    T3 item3,
    T4 item4,
    T5 item5,
    T6 item6,
    T7 item7)

Makes a tuple holding seven elements, which may be of different types.

参数

名称类型默认值说明
项 1T1—The first element.
项 2T2—The second element.
项 3T3—The third element.
项 4T4—The fourth element.
项 5T5—The fifth element.
项 6T6—The sixth element.
项 7T7—The seventh element.

返回

结果(T1, T2, T3, T4, T5, T6, T7)

重载 9/9

签名
创建元组 -> ValueTuple<T1, T2, T3, T4, T5, T6, T7, (T8)>
    项 1: T1
    项 2: T2
    项 3: T3
    项 4: T4
    项 5: T5
    项 6: T6
    项 7: T7
    项 8: T8
ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8>> Create(
    T1 item1,
    T2 item2,
    T3 item3,
    T4 item4,
    T5 item5,
    T6 item6,
    T7 item7,
    T8 item8)

Makes a tuple holding eight elements, which may be of different types.

参数

名称类型默认值说明
项 1T1—The first element.
项 2T2—The second element.
项 3T3—The third element.
项 4T4—The fourth element.
项 5T5—The fifth element.
项 6T6—The sixth element.
项 7T7—The seventh element.
项 8T8—The eighth element.

返回

结果ValueTuple<T1, T2, T3, T4, T5, T6, T7, (T8)>

备注

The eighth element is stored in a nested one-element tuple (the Rest field), as every tuple of more than seven elements is; ValueTupleRoutines.Length, ValueTupleRoutines.Get and ValueTupleRoutines.ToArray look through the nesting and count it as eight elements.

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

相等

函数

Whether two tuples of the same type hold equal elements, position by position, using each element type's default equality.

签名
相等(左侧: TTuple, 右侧: TTuple) -> 真否
bool Equals(TTuple left, TTuple right)

参数

名称类型默认值说明
左侧TTuple—The first tuple.
右侧TTuple—The second tuple.

返回

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

格式化

函数

Writes a tuple as text, its elements separated by commas inside parentheses, for example (1, apple, True).

签名
格式化(元组: 任意) -> 文本
string Format(object tuple)

参数

名称类型默认值说明
元组任意—The tuple to write. Null throws System.ArgumentNullException and a value that is not a tuple throws System.ArgumentException.

返回

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

获取项

函数

The element at a position in a tuple, counting from zero; use ValueTupleRoutines.TryGet when the position may be out of range.

签名
获取项(元组: 任意, 索引: 整数) -> 任意
object Get(object tuple, int index)

参数

名称类型默认值说明
元组任意—The tuple to read. Null throws System.ArgumentNullException and a value that is not a tuple throws System.ArgumentException.
索引整数—The zero-based position; a position below zero or at or past the tuple's length throws System.IndexOutOfRangeException.

返回

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

哈希

函数

A hash code combining the tuple's elements, so equal tuples get equal codes; use it for bucketing or quick inequality checks.

签名
哈希(元组: 任意) -> 整数
int Hash(object tuple)

参数

名称类型默认值说明
元组任意—The tuple to hash; null answers 0.

返回

结果整数

备注

The code is randomised per process, so do not store it or compare it across runs. This does not check that the value is a tuple: any other value answers its own hash code.

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

是否为元组

函数

Whether Value is a tuple, so the other tuple routines can read it.

签名
是否为元组(值: 任意) -> 真否
bool IsTuple(object value)

参数

名称类型默认值说明
值任意—The value to check; null answers false.

返回

结果真否

备注

This accepts any value that exposes its elements by position, which includes the older reference-type System.Tuple classes as well as value tuples; ValueTupleRoutines.IsTupleType is stricter and accepts only value tuple types.

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

是否为元组类型

函数

Whether Type is a value tuple type of any size, from the empty tuple up to seven elements plus a nested rest; for checking a type before you have a value of it.

签名
是否为元组类型(类型: Type) -> 真否
bool IsTupleType(Type type)

参数

名称类型默认值说明
类型Type—The type to check; null answers false. The reference-type System.Tuple classes answer false.

返回

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

长度

函数

How many elements a tuple holds, counting through the nested rest of a tuple with more than seven elements.

签名
长度(元组: 任意) -> 整数
int Length(object tuple)

参数

名称类型默认值说明
元组任意—The tuple to measure. Null throws System.ArgumentNullException and a value that is not a tuple throws System.ArgumentException.

返回

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

结构比较

函数

Orders two tuples element by element like ValueTupleRoutines.Compare, with Comparer ordering each pair of elements, for example to sort text elements case-insensitively.

签名
结构比较(左侧: 任意, 右侧: 任意, 比较器: IComparer) -> 整数
int StructuralCompare(
    object left,
    object right,
    IComparer comparer)

参数

名称类型默认值说明
左侧任意—The first tuple; null or a value that does not support structural comparison throws System.ArgumentException.
右侧任意—The second tuple; null sorts before any tuple, and a tuple of a different type throws System.ArgumentException.
比较器IComparer—The comparer that orders each pair of elements; null throws System.ArgumentNullException.

返回

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

结构相等

函数

Whether two tuples hold equal elements, position by position, with Comparer deciding each pair, for example to compare text elements case-insensitively.

签名
结构相等 -> 真否
    左侧: 任意
    右侧: 任意
    比较器: IEqualityComparer
bool StructuralEquals(
    object left,
    object right,
    IEqualityComparer comparer)

参数

名称类型默认值说明
左侧任意—The first tuple; null or a value that does not support structural comparison throws System.ArgumentException.
右侧任意—The second tuple; null, or a tuple of a different type, answers false.
比较器IEqualityComparer—The comparer that decides whether two elements are equal; null throws System.ArgumentNullException.

返回

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

结构哈希

函数

A hash code for a tuple in which each element is hashed by Comparer, to pair with ValueTupleRoutines.StructuralEquals using the same comparer, for example to treat text elements case-insensitively.

签名
结构哈希(元组: 任意, 比较器: IEqualityComparer) -> 整数
int StructuralHash(object tuple, IEqualityComparer comparer)

参数

名称类型默认值说明
元组任意—The tuple to hash; null or a value that does not support structural comparison throws System.ArgumentException.
比较器IEqualityComparer—The comparer that hashes each element; null throws System.ArgumentNullException.

返回

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

转为数组

函数

Copies a tuple's elements into a new array in order, so they can be handled as a list.

签名
转为数组(元组: 任意) -> 任意数组
object[] ToArray(object tuple)

参数

名称类型默认值说明
元组任意—The tuple to copy. Null throws System.ArgumentNullException and a value that is not a tuple throws System.ArgumentException.

返回

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

尝试获取项

函数

Reads the element at a position in a tuple without throwing, telling you whether there was one.

签名
尝试获取项(元组: 任意, 索引: 整数) -> (结果: 真否, 值: 任意)
bool TryGet(object tuple, int index, out object value)

参数

名称类型默认值说明
元组任意—The tuple to read; null or a value that is not a tuple answers false.
索引整数—The zero-based position; out of range answers false.

返回

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

验证元组

函数

Checks that a value is a tuple and throws if it is not, so a graph fails at a clear point instead of further on.

签名
验证元组(元组: 任意)
void ValidateTuple(object tuple)

参数

名称类型默认值说明
元组任意—The value to check. Null throws System.ArgumentNullException and a value that is not a tuple throws System.ArgumentException.
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
元组操作
所属包
标准库