Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq Select 5 items per Iteration [duplicate]

Tags:

c#

linq

Linq Select 5 items each time based on our enumerator

Our List e.g "theList" has 100 items, Want to go through the list and Select 5 items in each iterations,

Sample Code, which we want to change this into our desired result :

        theList = dt.AsEnumerable()             .Select(row => new CustItem             {                 Name = row.Field<string>("tName"),                 Title = row.Field<string>("tTitle"),             }).ToList(); 

We should Iterate it within a loop and process on the selected 5 items each time, or pass it to our other methods :

something like it :

for (int i=0; i < 20 ; i++) 

I want to use "i" enumerator on the linq select statement and make a multiplicity to make the boundaries of our new resultset.

like image 244
Kasrak Avatar asked Jul 11 '12 07:07

Kasrak


1 Answers

for (int i=0; i < 20 ; i++) {     var fiveitems = theList.Skip(i*5).Take(5); } 
like image 96
Govind Malviya Avatar answered Sep 17 '22 17:09

Govind Malviya