C# 7 ValueTuple 是否有类似于 Python 切片的功能?C# 中值元组的语法类似于 Python,但例如我找不到从元组获取子元组的优雅方法。
在 Python 3 中:
tuple = (1,2,3)
subtuple = t[:2] #subtuple is (1, 2)
在 C# 7 中:
var tuple = (1,2,3) //Very similar to Python!
var subtuple = (tuple.Item1, tuple.Item2) //Not very elegant, especially for bigger tuples