有一种将Tuple转换为ValueTuple的简便方法吗? [英] Is there a shorthand way to convert a Tuple to a ValueTuple?
问题描述
我刚刚将DLL文件包含到我的项目中,并且正在使用一种返回 List< Tuple>
的方法.我直到最近才意识到C#7中的 ValueTuple
数据类型,并希望使用它代替返回的普通元组.我知道我可以遍历并手动进行转换,但是如果可能的话,我想避免这样做,并且想知道是否有人知道将元组转换为ValueTuple的简便方法吗?如果我一无所知并且不可能做到这一点,那么如果有人可以让我意识到实现转换的最有效方式,我将不胜感激.
I have just included a DLL file into my project and am using a method which returns a List<Tuple>
. I have only recently became aware of the ValueTuple
datatype in C# 7 and want to use it instead of the normal Tuples which are returned. I am aware that I could loop through and do the conversion manually however I would like to avoid doing this if possible and was wondering if anyone was aware of a shorthand way to casting a Tuple to a ValueTuple? If I am being ignorant and this isn't possible then I would be grateful if someone could make me aware of the most performant way I could achieve this conversion.
我一直在寻找 .ToValueTuple()
方法,并在函数上使用了基本的强制类型转换,毫无疑问地返回了列表.
I have looked for a .ToValueTuple()
method and using a basic cast on the function returning the List with no joy.
尝试时:
List<(string entityName, int min, int average, int max)> tupTest = trs.GetEntityStats();
我收到错误:
无法将源类型'System.Collections.Generic.List>'转换为目标类型'System.Collections.Generic.List<((字符串实体名称,整数最小值,整数平均值,整数最大值)>'
Cannot convert source type 'System.Collections.Generic.List>' to target type 'System.Collections.Generic.List<(string entityName, int min, int average, int max)>'