开发者

How to skip(m).take(n) from a List<T>?

Given:

List<int> list = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

How do I implement the following code?

va开发者_Go百科r list2 = list.skip(2).take(5);


Your sample code will work as long as you include System.Linq in your using statements (and fix your method names .Skip(2) and .Take(5)).

The reason your code did not work out of the box is that .Skip and .Take are extension methods (as opposed to methods defined in the List class) found in the 'System.Linq' namespace.


Have a look at the samples in the following link and its more easy to go with

LINQ 101 Sample

http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜