在 JavaScript ES6中,您可以像下面这样解构数组:
const [a,b,...rest] = someArray;
其中 a
是数组中的第一个元素,b
是第二个元素,rest
是包含其余元素的数组。
我知道在 C # 7中可以在赋值过程中解构元组,但是找不到任何与解构数组/可枚举数有关的东西,比如:
var (a,b) = someTuple;
我有一个 IEnumerable
,其中我需要第一个和第二个元素作为变量,我需要其余的元素作为另一个 IEnumable。我有一个解决方案,但觉得解体将看起来更干净。