This is the code to display the elements of an array and the number of times they occur using System;
Take a Console Application and write the code in Main method
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationlinq
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 10, 20, 30, 30, 10 };
//use the Group By function with a lambda
//expression
var q = arr.GroupBy(a => a);
//use the Generic interface IGrouping
foreach (IGrouping<int, int> z in q)
{
Console.WriteLine(z.Key + "---" + z.Count());
}
}
}
}
output:
10--2
20--1
30--2