Create a SortedSet that contains elements copied from a specified enumerable collection in CSharp

Description

The following code shows how to create a SortedSet that contains elements copied from a specified enumerable collection.

Example


using System;/*www  .j  a  v  a 2  s  . c  o  m*/
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        MyComparer myComparer = new MyComparer();
        SortedSet<string> allVehicles = new SortedSet<string>(new String[]{});

        allVehicles.Add("A");
        allVehicles.Add("T");
        allVehicles.Add("B");

    
        foreach(String i in allVehicles){
           Console.WriteLine(i);
        }
    }
}

class MyComparer : EqualityComparer<string>
{
    public override bool Equals(string s1, string s2)
    {
        return s1.Equals(s2, StringComparison.CurrentCultureIgnoreCase);
    }
    public override int GetHashCode(string s)
    {
        return base.GetHashCode();
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary