This program is for count a total no of duplicate element in given array values.
Hope this is helpful for you.
class Program
{
static void Main(string[] args)
{
int input = 0;
int[] arrayvalue = new int[] { };
int[] Temp_array = new int[] { };
int[] duplicate_array = new int[] { };
Console.Write("Enter no of object that you want to display:-");
input = Convert.ToInt32(Console.ReadLine());
arrayvalue = new int[input];
Temp_array = new int[input];
duplicate_array = new int[input];
int DuplicateCount = 0;
for (int i = 0; i <= arrayvalue.Length - 1; i++)
{
Console.Write("Element at {0} - ", i);
arrayvalue[i] = Convert.ToInt32(Console.ReadLine());
}
for (int k = 0; k <= arrayvalue.Length - 1; k++)
{
int count = 0;
if(Temp_array.Length == 0 || !Temp_array.Contains(arrayvalue[k]))
{
Temp_array[k] = arrayvalue[k];
}
else
{
duplicate_array[k] = arrayvalue[k];
}
}
Array.Clear(Temp_array,0,input);//Clear array
Console.WriteLine("----------------------");
for (int j =0;j<duplicate_array.Count();j++)
{
//get list of duplicate element in an array.
if (duplicate_array[j] != 0 && !Temp_array.Contains(duplicate_array[j]))
{
Temp_array[j] = duplicate_array[j];
DuplicateCount++;
}
}
Console.WriteLine("The total no of duplicate element is - {0}:",DuplicateCount);
Console.ReadLine();
}
}
For Ex input :1,2,1,2,1
output:The total no of duplicate element is 2.