using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpGitHubPgm
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 1, 2, 3, 1, 5, 2, 1 };
Dictionary<int, int> storeRepeatedNumber = new Dictionary<int, int>();
Console.WriteLine("To find the repeatative element in the array");
for (int i = 0; i < arr.Length; i++)
{
if (storeRepeatedNumber.ContainsKey(arr[i]))
{
int previousValue = storeRepeatedNumber[arr[i]];
storeRepeatedNumber[arr[i]] = previousValue + 1;
}
else
{
storeRepeatedNumber.Add(arr[i], 1);
}
}
foreach (KeyValuePair<int,int> item in storeRepeatedNumber)
{
Console.WriteLine("{0} Occurs {1} times", item.Key,item.Value);
}
Console.ReadLine();
}
}
}In this code snippet you will learn how to Find the Count of Repetitive Number using Dictionary.
