Lets say that i have a big list of string called "lines" and it holds all lines from a text file (Its usually big numbers around 100k - 1mil lines)
List<string> lines = File.ReadAllLines("Lines.txt");
And my problem is that i would need to split the file (Or the list) based on what chunk size the user inputs. So lets say that we have 10k Lines in
Lines.txt
and user imputs chunks of 4400 lines
File1 = 4400 Lines
File2 = 4400 Lines
File3 = 1200 Lines
I tried using something like this that my colleague recommended but i dont understand it and it does not work.
public static class ListExtensions
{
public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize)
{
return source
.Select((x, i) => new { Index = i, Value = x })
.GroupBy(x => x.Index / chunkSize)
.Select(x => x.Select(v => v.Value).ToList())
.ToList();
}
}
I would appreciate any recommendations or help on how i could solve this.