top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Split List into Sub list in C# using LINQ ?

0 votes
396 views
How to Split List into Sub list in C# using LINQ ?
posted May 3, 2016 by Jayshree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AbundantcodeApp
{
    class Program
    {
        static void Main(string[] args)
        {

            List<string> strLst = new List<string>();
            strLst.Add("Android Development");
            strLst.Add("Windows Phone Development");
            strLst.Add("Abundantcode Programming");
            var result = Split(strLst);
            Console.ReadLine();
        }

        public static List<List<string>> Split(List<string> input)
        {
            return input.Select((item1, index) => new { Index = index, Value = item1 })
                .GroupBy(x => x.Index / 3)
                .Select(x => x.Select(v => v.Value).ToList())
                .ToList();
        }


    }

}
answer May 3, 2016 by Shivaranjini
...