C# Comparer Comparer

Description

Comparer Comparer initializes a new instance of the Comparer class using the specified System.Globalization.CultureInfo.

Syntax

Comparer.Comparer has the following syntax.


public Comparer(
  CultureInfo culture
)

Parameters

Comparer.Comparer has the following parameters.

  • culture - The System.Globalization.CultureInfo to use for the new Comparer.

Example

The following code example shows how Compare returns different values depending on the culture associated with the Comparer.


using System;// w  ww  . j  a  v  a 2  s . c  o m
using System.Collections;
using System.Globalization;


public class SamplesComparer  {

   public static void Main()  {
      String str1 = "abc";
      String str2 = "aabe";

      Comparer myCompIntl = new Comparer( new CultureInfo( "es-ES", false ) );
      Console.WriteLine( "   International Sort: {0}", myCompIntl.Compare( str1, str2 ) );

   }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack