本文介绍了有一种将Tuple转换为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();

我收到错误:

推荐答案

TupleExtensions类具有 ToTuple ToValueTuple 方法.

这篇关于有一种将Tuple转换为ValueTuple的简便方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-09 02:28