// This is optimized code
static void Main(string[] args)
{
int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 };
for (int i = 0; i < arr.Length;i++)
{
int tpt = 0;
if(arr.Contains(arr[i]))
{
tpt = arr.Where(x => x == arr[i]).ToArray().Count();
}
Console.WriteLine(string.Format("The value is {0} and count is {1}", arr[i], tpt));
}
Console.ReadLine();
}