tobbbe
12/3/2013 - 10:19 AM

create distinct (max en av varje) list and then sort it, HashSet, array

create distinct (max en av varje) list and then sort it, HashSet, array

//Create hashset object of the int type
HashSet<int> objHash = new HashSet<int>();
// add items to hashset object
objHash.Add(14);
objHash.Add(12);
objHash.Add(11);
objHash.Add(13);

// Print all elements of the hashset object
Console.WriteLine("before sort");
foreach (int i in objHash)
{
    Console.WriteLine(i);
}

//Declare a new Array object of int type
int[] arrInt;
// bind items to array from hashset object
arrInt = objHash.ToArray();
// Sort the array
Array.Sort(arrInt);
// Clear hashset object
objHash.Clear();
//Merge the array into hashset object with sort order
objHash.UnionWith(arrInt);
//Print the all items of the hashset object
Console.WriteLine("After sort");
foreach (int i in objHash)
{
    Console.WriteLine(i);
}