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
精慕HU
倚天杖
随时随地看视频慕课网APP
相关分类