Quantcast
Channel: BlogFodder
Viewing all articles
Browse latest Browse all 23

Split Large List Into Chunks Of A Specified Size

$
0
0

I had the need recently to split up a List of objects (2.5 million rows) into smaller lists so I could batch insert into a database. I stumbled on this method, and it's lightning fast for splitting large lists into smaller chunks of whatever size you want.

        public static List<List<object>> SplitList(List<object> locations, int nSize = 30)
{
List<List<object>> list = new List<List<object>>();

for (int i = 0; i < locations.Count; i += nSize)
{
list.Add(locations.GetRange(i, Math.Min(nSize, locations.Count - i)));
}

return list;
}

Viewing all articles
Browse latest Browse all 23

Latest Images

Trending Articles





Latest Images