我刚刚将一个 DLL 文件包含到我的项目中,并且正在使用一种返回 List<Tuple>
的方法。 .我最近才意识到 ValueTuple
C# 7 中的数据类型,并希望使用它而不是返回的普通元组。我知道我可以循环并手动进行转换,但是我想尽可能避免这样做,并且想知道是否有人知道将 Tuple 转换为 ValueTuple 的简写方法?如果我是无知的并且这是不可能的,那么如果有人能让我知道我可以实现这种转换的最有效方式,我将不胜感激。
我找了一个.ToValueTuple()
方法并对返回 List 的函数使用基本强制转换,但没有任何乐趣。
尝试时:
List<(string entityName, int min, int average, int max)> tupTest = trs.GetEntityStats();
我收到错误:
Cannot convert source type 'System.Collections.Generic.List>' to target type 'System.Collections.Generic.List<(string entityName, int min, int average, int max)>'
最佳答案
TupleExtensions Class有 ToTuple
和 ToValueTuple
方法。
关于.net - 是否有将元组转换为 ValueTuple 的简写方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57149107/