I have an IEnumerable<string> which I would like to split into groups of three so if my input had 6 items i would get a IEnumerable<IEnumerable<string>> returned with two items each of which would contain an IEnumerable<string> which my string contents in it.
I am looking for how to do this with Linq rather than a simple for loop
Thanks
Note that this will return an
IEnumerable<IGrouping<int,string>>which will be functionally similar to what you want. However, if you strictly need to type it asIEnumerable<IEnumerable<string>>(to pass to a method that expects it in C# 3.0 which doesn’t support generics variance,) you should useEnumerable.Cast: