int[] array = { 5, 7, 3, 5, 3, 6, 5, 2, 1 };
Sort by ascending first, then reverse array
Array.Sort(array);
Array.Reverse(array);
foreach (var item in array) { Console.Write(item); }
To find which number has max occurencies try this:
var numOccurrencies = new Dictionary<int, int>();
int numberWithMaxOccurrencies = 0;
int maxOccurrences = 0;
foreach (var item in array)
{
if (!numOccurrencies.ContainsKey(item))
{
numOccurrencies.Add(item, 0);
}
numOccurrencies[item]++;
if (numOccurrencies[item] > maxOccurrences)
{
numberWithMaxOccurrencies = item;
maxOccurrences = numOccurrencies[item];
}
}
Console.WriteLine("Number {0} has {1} occurrencies.", numberWithMaxOccurrencies, maxOccurrences);