To getting use of IGrouping interface in LINQ.

Posted by Jitendrasoft09 under C# category on | Points: 40 | Views : 1566
using System;
using System.Collections.Generic;
using System.Linq;

class JkExample{

static void Main(string[] args) {

List<string> listobject = new List<string>() {
"apple", "grape", "banana”, "mango"};

IEnumerable<IGrouping<char, string>> mydata = from e in listobject
group e by e[0];

foreach (IGrouping<char, string> group in mydata) {
Console.WriteLine("Group key: {0}", group.Key);
foreach (string value in group) {
Console.WriteLine("Group item: {0}", value);


Comments or Responses

Login to post response