ASP tutorial. NET get the duplicate data code in an array
The following provides five different ways to remove duplicate data from the data and count the number of repetitions.
dictionary<int, int> dic = new Dictionary ();
int[] arr = new int[] {1, 5, 2, 6, 7, 1, 5, 4, 1, 6, 8, 7, 6};
foreach (int i in arr)
{
Try
{
Dic.add (i, I);
}
catch (Exception err)
{
//.... ...
}
}
Method Two
int[] arr = new int[] {1, 5, 2, 6, 7, 1, 5, 4, 1, 6, 8, 7, 6};
int n = arr.length-arr.distinct (). Count ();
Method Three
int[] ary = new int[] {1, 3, 3, 4, 5, 4};
var q = from X in ary
Group x by x into Y
Select {Y.key,y.count ()};
Method Four
int[] arr = new int[] {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7};
var GS = arr.groupby (i => i). by (I => i.count ());
Console.WriteLine (Gs.lastordefault (). ToArray () [0]);
Method Five
Int[] arr = {1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5};
var linqer =
From A in arr
Group Arr by A into B
by B.count ()
Select New
{
B.key,
Count = B.count ()
};
foreach (var i in Linqer)
{
Console.WriteLine ("{0} appears {1} times", I.key, I.count);
}