Comparer Class Compares two objects for equivalence, where string comparisons are case-sensitive. : IComparer « Collections Data Structure « C# / C Sharp






Comparer Class Compares two objects for equivalence, where string comparisons are case-sensitive.

  
using System;
using System.Collections;
using System.Globalization;


public class SamplesComparer  {
   public static void Main()  {
      String str1 = "abc";
      String str2 = "Abc";
      Console.WriteLine( "Comparing {0} and {1}", str1, str2 );

      Console.WriteLine( Comparer.DefaultInvariant.Compare( str1, str2 ) );

      Comparer myCompIntl = new Comparer( new CultureInfo( "es-ES", false ) );
      Console.WriteLine( myCompIntl.Compare( str1, str2 ) );

      Comparer myCompTrad = new Comparer( new CultureInfo( 0x040A, false ) );
      Console.WriteLine( myCompTrad.Compare( str1, str2 ) );
   }
}

   
    
  








Related examples in the same category

1.IComparer Interface Exposes a method that compares two objects.
2.EqualityComparer(T) Class provides a base class for implementations of the IEqualityComparer generic interface.
3.Compares the two values passed in and checks if they're value-wise the same.