Create SortedSet using a specified comparer in CSharp

Description

The following code shows how to create SortedSet using a specified comparer.

Example


/*  w ww.  j  a  va  2s. co m*/
using System;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {
        SortedSet<String> allVehicles = new SortedSet<string>(new My());

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

    
        foreach(String i in allVehicles){
           Console.WriteLine(i);
        }        
    }
}
public class My : IComparer<string>
{
    public int Compare(string x, string y)
    {
        return 1;
    }
}

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