public class Example
{
public static void Main()
{
Console.Write("<< Linq - GroupBy 출력 예제 >> \n");
List<int> numbers = new List<int>() { 55, 64, 300, 74, 1987, 8, 299, 429, 546, 308 };
IEnumerable<IGrouping<int, int>> query = from number in numbers
group number by number % 2;
foreach (var group in query)
{
Console.WriteLine(group.Key == 0 ? "\nEven numbers:" : "\nOdd numbers:");
foreach (int i in group)
Console.WriteLine(i);
}
Console.WriteLine(System.Environment.NewLine);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}