GroupBy
In this chapter you will learn:
Get to know GroupBy operator
using System;/*from ja va 2 s. com*/
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
string[] names = { "Java", "C#", "Javascript", "SQL", "Oracle", "Python", "C++", "C", "HTML", "CSS" };
IEnumerable< IGrouping<int,string>> grouping = names.GroupBy(s => s.Length);
foreach (IGrouping<int, string> group in grouping)
{
Console.WriteLine("Key: " + group.Key);
foreach (string filename in group)
Console.WriteLine(" - " + filename);
}
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Linq Operators