mscorlib 2.0.0.0 4.0.0.0 System.Object System.Collections.Generic.IComparer<System.String> System.Collections.Generic.IEqualityComparer<System.String> System.Collections.IComparer System.Collections.IEqualityComparer System.Runtime.InteropServices.ComVisible(true)

An object derived from the class embodies string-based comparison, equality, and hash code operations that take into account both case and culture-specific comparison rules. You can use the class to create a type-specific comparison to sort the elements in a generic collection. Classes such as , , , and use the class for sorting purposes.

A comparison operation that is represented by the class is defined to be either case-sensitive or case-insensitive, and use either word (culture-sensitive) or ordinal (culture-insensitive) comparison rules. For more information about word and ordinal comparison rules, see .

## Implemented Properties

You might be confused about how to use the class properties because of a seeming contradiction. The class is declared abstract (MustInherit in Visual Basic), which means its members can be invoked only on an object of a class derived from the class. The contradiction is that each property of the class is declared static (Shared in Visual Basic), which means the property can be invoked without first creating a derived class.

You can call a property directly because each property actually returns an instance of an anonymous class that is derived from the class. Consequently, the type of each property value is , which is the base class of the anonymous class, not the type of the anonymous class itself. Each class property returns a object that supports predefined case and comparison rules.

Represents a string comparison operation that uses specific case and culture-based or ordinal comparison rules.

- Constructor
  2.0.0.0
  4.0.0.0
  To be added.

  Initializes a new instance of the class.

- Method
  2.0.0.0
  4.0.0.0
  System.Int32 `` ``

  The method is more efficient than the method because the and parameters do not have to be unboxed to perform the comparison.

  When overridden in a derived class, compares two objects and returns an indication of their relative sort order.

  A signed integer that indicates the relative values of and , as shown in the following table.

  Value

  Meaning

  Less than zero

  is less than .

  -or-

  is null.

  Zero

  is equal to .

  Greater than zero

  is greater than .

  -or-

  is null.

  An object to compare to . An object to compare to .
- Method
  2.0.0.0
  4.0.0.0
  System.Int32 `` ``

  The method is more efficient than the method because the and parameters do not have to be unboxed to perform the comparison.

  When overridden in a derived class, compares two strings and returns an indication of their relative sort order.

  A signed integer that indicates the relative values of and , as shown in the following table.

  Value

  Meaning

  Less than zero

  is less than .

  -or-

  is null.

  Zero

  is equal to .

  Greater than zero

  is greater than .

  -or-

  is null.

  A string to compare to . A string to compare to .
- Method
  2.0.0.0
  4.0.0.0
  System.StringComparer `` `` To be added.

  Creates a object that compares strings according to the rules of a specified culture.

  A new object that performs string comparisons according to the comparison rules used by the parameter and the case rule specified by the parameter.

  A culture whose linguistic rules are used to perform a string comparison. true to specify that comparison operations be case-insensitive; false to specify that comparison operations be case-sensitive.
- Property
  2.0.0.0
  4.0.0.0
  System.StringComparer To be added.

  The returned by the property can be used when strings are linguistically relevant. For example, if strings are displayed to the user, or if strings are the result of user interaction, culture-sensitive string comparison should be used to order the string data.

  The current culture is the object associated with the current thread.

  The property actually returns an instance of an anonymous class derived from the class.

  Each call to the property get accessor returns a new object, as the following code shows.

  code reference: System.StringComparer.CurrentCulture#1

  To improve performance, you can store the object in a local variable rather than retrieve the value of the property multiple times.

  Gets a object that performs a case-sensitive string comparison using the word comparison rules of the current culture.

- Property
  2.0.0.0
  4.0.0.0
  System.StringComparer To be added.

  The current culture is the object associated with the current thread.

  The returned by the property can be used when strings are linguistically relevant but their case is not. For example, if strings are displayed to the user but case is unimportant, culture-sensitive, case-insensitive string comparison should be used to order the string data.

  The property actually returns an instance of an anonymous class derived from the class.

  Each call to the property get accessor returns a new object, as the following code shows.

  code reference: System.StringComparer.CurrentCulture#2

  To improve performance, you can store the object in a local variable rather than retrieve the value of the property multiple times.

  Gets a object that performs case-insensitive string comparisons using the word comparison rules of the current culture.

- Method
  2.0.0.0
  4.0.0.0
  System.Boolean `` ``

  The method is more efficient than the method because the and parameters do not have to be unboxed to perform the comparison.

  When overridden in a derived class, indicates whether two objects are equal.

  true if and refer to the same object, or and are both the same type of object and those objects are equal; otherwise, false.

  An object to compare to . An object to compare to .
- Method
  2.0.0.0
  4.0.0.0
  System.Boolean `` ``

  The method is more efficient than the method because the and parameters do not have to be unboxed to perform the comparison.

  When overridden in a derived class, indicates whether two strings are equal.

  true if and refer to the same object, or and are equal; otherwise, false.

  A string to compare to . A string to compare to .
- Method
  2.0.0.0
  4.0.0.0
  System.Int32 ``

  The method is more efficient than the method because the parameter does not have to be unboxed to perform the operation.

  The method allocates an amount of memory that is proportional to the size of to calculate the hash code of . In the case of large strings, trying to retrieve the hash code can throw an . Instead, you can use an alternate algorithm that allocates a fixed amount of memory when calculating hash codes. To use this algorithm, add the <NetFx45_CultureAwareComparerGetHashCode_LongStrings> element to the <runtime> section of your application's configuration file.

  When overridden in a derived class, gets the hash code for the specified object.

  A 32-bit signed hash code calculated from the value of the parameter.

  An object.
- Method
  2.0.0.0
  4.0.0.0
  System.Int32 ``

  The method is more efficient than the method because the parameter does not have to be unboxed to perform the operation.

  The method allocates an amount of memory that is proportional to the size of to calculate the hash code of . In the case of large strings, trying to retrieve the hash code can throw an . Instead, you can use an alternate algorithm that allocates a fixed amount of memory when calculating hash codes. To use this algorithm, add the <NetFx45_CultureAwareComparerGetHashCode_LongStrings> element to the <runtime> section of your application's configuration file.

  When overridden in a derived class, gets the hash code for the specified string.

  A 32-bit signed hash code calculated from the value of the parameter.

  A string.
- Property
  2.0.0.0
  4.0.0.0
  System.StringComparer To be added.

  The returned by the property compares strings in a linguistically relevant manner, but it is not suitable for display in any particular culture. Its major application is to order strings in a way that will be identical across cultures.

  The invariant culture is the object returned by the property.

  The property actually returns an instance of an anonymous class derived from the class.

  Gets a object that performs a case-sensitive string comparison using the word comparison rules of the invariant culture.

- Property
  2.0.0.0
  4.0.0.0
  System.StringComparer To be added.

  The returned by the property compares strings in a linguistically relevant manner that ignores case, but it is not suitable for display in any particular culture. Its major application is to order strings in a way that will be identical across cultures.

  The invariant culture is the object returned by the property.

  The property actually returns an instance of an anonymous class derived from the class.

  Gets a object that performs a case-insensitive string comparison using the word comparison rules of the invariant culture.

- Property
  2.0.0.0
  4.0.0.0
  System.StringComparer To be added.

  The returned by the property performs a simple byte comparison that is independent of language. This is most appropriate when comparing strings that are generated programmatically or when comparing case-sensitive resources such as passwords.

  The property actually returns an instance of an anonymous class derived from the class.

  Gets a object that performs a case-sensitive ordinal string comparison.

- Property
  2.0.0.0
  4.0.0.0
  System.StringComparer To be added.

  The returned by the property treats the characters in the strings to compare as if they were converted to uppercase using the conventions of the invariant culture, and then performs a simple byte comparison that is independent of language. This is most appropriate when comparing strings that are generated programmatically or when comparing case-insensitive resources such as paths and filenames.

  The property actually returns an instance of an anonymous class derived from the class.

  Gets a object that performs a case-insensitive ordinal string comparison.