SortedSetset = new SortedSet (); List numbers = new List () { 1, 3, 2, 5, 4 }; set.AddAll(numbers); // set now contains { 1, 2, 3, 4, 5 }
SortedSetIn this example, we create an empty SortedSet and an array of strings. We pass the array to the AddAll method, which adds the values to the SortedSet in alphabetical order. The SortedSet class is part of the System.Collections.Generic namespace in the .NET Framework.set = new SortedSet (); string[] fruits = new string[] { "apple", "banana", "pear", "mango" }; set.AddAll(fruits); // set now contains { "apple", "banana", "mango", "pear" }