score:9
Accepted answer
it groups the items into the number of parts that you specify. the i++ will increment for each item and apply the modulus operator so that it puts it in the correct number of buckets. so the first item goes in bucket 0, 2nd in bucket 1, 3rd in bucket 2, 4th in bucket 0, etc...
score:6
while keith rousseau is correct, i would argue that the idea is a rather bad way to achieve this. you can achieve it more purely (i.e., without having to mutate a captured variable) via:
var splits = list.select((item, index) => new { item = item, index = index })
.groupby(pair => pair.index % parts, element => element.item)
.select(group => group.asenumerable());
Source: stackoverflow.com
Related Query
- How does this linq code that splits a sequence work?
- How does this RavenDB linq query work
- How does this Moq Test work mainly regarding linq syntax?
- How can i fix this method using Linq so that the test (which should already work because the result is correct) works?
- How are people unit testing code that uses Linq to SQL
- What does this C# code with an "arrow" mean and how is it called?
- How does LINQ expression syntax work with Include() for eager loading
- how does except method work in linq
- How does Linq work (behind the scenes)?
- How does a LINQ expression know that Where() comes before Select()?
- Does this LINQ code perform multiple lookups on the original data?
- How does linq actually execute the code to retrieve data from the data source?
- How does this LINQ Expression work?
- How can I switch that code to use LINQ
- How can I combine this code into one or two LINQ queries?
- How does OrderBy in LINQ work (behind the scenes)?
- Why does .Equals not work in this LINQ example?
- linq - how do you do a query for items in one query source that are not in another one?
- How can I further simplify this piece of LINQ code
- How does linq Expression<TDelegate> assignment work on a language syntax level
- How to code the partial extensions that Linq to SQL autogenerates?
- How to render this map-reduce javascript code to an equivalent LINQ Select-Aggregate?
- Why does the StringComparison.InvariantCultureIgnoreCase not work with this Db4o linq query?
- How can I fix this LINQ so that it treats a pairs of vals as a distinct value?
- How can I modify this C# code so that Visual Studio recognizes that I'm not an idiot?
- How to work around the fact that Linq to SQL is using separate SQL DELETE statements for each item in DeleteAllOnSubmit
- How do i convert this linq code to inline sql
- How does this work? LINQ to Entities triggers loading of assemblies?
- How does linq concat work under the hood?
- How does linq lambdas work inside a loop?
More Query from same tag
- How to use Linq to combine strings and lists?
- LINQ to XML: Collapse mutliple levels to single list
- Select bottom N from Generic List
- Function that returns a Generic List
- How to use xpath in Linq to check elements and attributes
- LINQ : Nesting this into a single query
- Detecting statically whether a linq expression is null
- Add second group by key field to existing Lambda Expression
- LINQ to SQL to find match in results that have multiple pipe separated values
- Using LINQ with different layers means I can't access a specific type
- Linq Empty String vs. Space
- Cleaner way to initialize & populate a new List<>?
- Writing C++11 LINQ-style Select
- Search and get all child nodes of XML node base on attribute id
- Linq to EF - concatenate column name
- Merge two DataTables to Single DataTable using LINQ, C#
- Linq nested list expression
- How can i get element in string by Linq
- Generate string from Grouping Linq Query
- List of strings into Bson Array
- Picking subset of emums using Linq (for binding w/ ComboBox
- C# Linq rows to column
- 'Model' does not contain a definition for 'Object"
- Null check for reflected property's value with Any() keyword
- C# LINQ DatabaseEntitie Query to first Value in Last Element results in Error
- Second result set returns null values - linq to entities
- DropDownList is not passing any values
- Will this LINQ query enumerate through the entire enumeration?
- Aggregate duplicate records with Linq in polymorphic case
- Linq - Sum of values inside a select statement with joins