本文介绍了如何创建命名引用类型元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的行创建一个名为ValueTuple的文件:

The following line creates a named ValueTuple:

var tuple = (a:1, b:2, c:3, d:4, e:5, f:6);

值类型不能有效地传递. C#7是否提供创建Tuple类型的命名元组的方法?

Value types can not be passed around efficiently. Does C#7 offer a way to create named tuples of the Tuple type?

推荐答案

如果您的意思是如果可以将其他名称附加到System.Tuple<...>实例的属性,则没有.

If you mean if there's a way to attach other names to the properties of System.Tuple<...> instances, no there isn't.

根据需要的原因,可以通过使用 TupleExtensions ,然后使用ToTuple重载.

Depending on why you want it, you might get around it by converting System.Tuple<...> instances to System.ValueTuple<...> instances using the ToValueTuple overloads in TupleExtensions and back using the ToTuple overloads.

如果您真的不需要元组,则可以使用Deconstruct重载或var (v1, .., vn) = tuple解构语法将它们解构为离散变量.

If you don't really need the tuples, you can deconstruct them into discrete variables using the Deconstruct overloads or the var (v1, .., vn) = tuple deconstruction syntax.

这篇关于如何创建命名引用类型元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 15:58