說,我有一個清單,我想得到它的一部分。假設我有 1000 個從 0 到 999 的數據。然後我想從“index1”到“index2”。
樣本數據是:
[0] = 100
[1] = 1520
....
[900] = 8975
....
[998] = 10
[999] = 4875
比如說我想從索引 900 到索引 998 獲取值。所以值返回應該是:
[0] = 8975
.....
[998] = 10
如何在 LINQ 中做到這一點?
您可以使用skip
,並take
為
List<int> list= new List<int>;
list.Skip(900).Take(100);
https://www.codingame.com/playgrounds/213/using-c-linq---a-practical-overview/skip-and-take
或者,您可以使用該GetRange
方法
List<int> list= new List<int>;
list.GetRange(900, 100); // Retrieves 100 items starting with index #900
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句