Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​StringComparer

Assembly: System.Runtime

Inheritance: object → StringComparer

Implemented Interfaces

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

Properties

public static StringComparer
CurrentCulture
Gets a <see cref="T:System.StringComparer" /> object that performs a case-sensitive string comparison using the word comparison rules of the current culture.
public static StringComparer
CurrentCultureIgnoreCase
Gets a <see cref="T:System.StringComparer" /> object that performs case-insensitive string comparisons using the word comparison rules of the current culture.
public static StringComparer
InvariantCulture
Gets a <see cref="T:System.StringComparer" /> object that performs a case-sensitive string comparison using the word comparison rules of the invariant culture.
public static StringComparer
InvariantCultureIgnoreCase
Gets a <see cref="T:System.StringComparer" /> object that performs a case-insensitive string comparison using the word comparison rules of the invariant culture.
public static StringComparer
Ordinal
Gets a <see cref="T:System.StringComparer" /> object that performs a case-sensitive ordinal string comparison.
public static StringComparer
OrdinalIgnoreCase
Gets a <see cref="T:System.StringComparer" /> object that performs a case-insensitive ordinal string comparison.

Methods

public int
Compare​(object x, object y)
When overridden in a derived class, compares two objects and returns an indication of their relative sort order.
Returns A signed integer that indicates the relative values of <paramref name="x" /> and <paramref name="y" /> , as shown in the following table. <list type="table"> <listheader> <term> Value</term> <description> Meaning</description> </listheader> <item> <term> Less than zero</term> <description> <paramref name="x" /> precedes <paramref name="y" /> in the sort order, or <paramref name="x" /> is <see langword="null" /> and <paramref name="y" /> is not <see langword="null" />.</description> </item> <item> <term> Zero</term> <description> <paramref name="x" /> is equal to <paramref name="y" />, or <paramref name="x" /> and <paramref name="y" /> are both <see langword="null" />.</description> </item> <item> <term> Greater than zero</term> <description> <paramref name="x" /> follows <paramref name="y" /> in the sort order, or <paramref name="y" /> is <see langword="null" /> and <paramref name="x" /> is not <see langword="null" />.</description> </item> </list>
x An object to compare to <paramref name="y" /> .
y An object to compare to <paramref name="x" /> .
public int
Compare​(string x, string y)
When overridden in a derived class, compares two strings and returns an indication of their relative sort order.
Returns A signed integer that indicates the relative values of <paramref name="x" /> and <paramref name="y" /> , as shown in the following table. <list type="table"> <listheader> <term> Value</term> <description> Meaning</description> </listheader> <item> <term> Less than zero</term> <description> <paramref name="x" /> precedes <paramref name="y" /> in the sort order, or <paramref name="x" /> is <see langword="null" /> and <paramref name="y" /> is not <see langword="null" />.</description> </item> <item> <term> Zero</term> <description> <paramref name="x" /> is equal to <paramref name="y" />, or <paramref name="x" /> and <paramref name="y" /> are both <see langword="null" />.</description> </item> <item> <term> Greater than zero</term> <description> <paramref name="x" /> follows <paramref name="y" /> in the sort order, or <paramref name="y" /> is <see langword="null" /> and <paramref name="x" /> is not <see langword="null" />.</description> </item> </list>
x A string to compare to <paramref name="y" /> .
y A string to compare to <paramref name="x" /> .
public static StringComparer
Create​(CultureInfo culture, bool ignoreCase)
Creates a <see cref="T:System.StringComparer" /> object that compares strings according to the rules of a specified culture.
Returns A new <see cref="T:System.StringComparer" /> object that performs string comparisons according to the comparison rules used by the <paramref name="culture" /> parameter and the case rule specified by the <paramref name="ignoreCase" /> parameter.
culture A culture whose linguistic rules are used to perform a string comparison.
ignoreCase <see langword="true" /> to specify that comparison operations be case-insensitive; <see langword="false" /> to specify that comparison operations be case-sensitive.
public static StringComparer
Create​(CultureInfo culture, CompareOptions options)
Creates a <see cref="T:System.StringComparer" /> object that compares strings according to the rules of a specified culture and string options.
Returns A new <see cref="T:System.StringComparer" /> object that performs string comparisons according to the comparison rules used by the <paramref name="culture" /> parameter and the specified <paramref name="options" /> .
culture A culture whose linguistic rules are used to perform a string comparison.
options A bitwise combination of the <see cref="T:System.Globalization.CompareOptions" /> values.
public bool
Equals​(object x, object y)
When overridden in a derived class, indicates whether two objects are equal.
Returns <see langword="true" /> if <paramref name="x" /> and <paramref name="y" /> refer to the same object, or <paramref name="x" /> and <paramref name="y" /> are both the same type of object and those objects are equal, or both <paramref name="x" /> and <paramref name="y" /> are <see langword="null" /> ; otherwise, <see langword="false" /> .
x An object to compare to <paramref name="y" /> .
y An object to compare to <paramref name="x" /> .
public bool
Equals​(string x, string y)
When overridden in a derived class, indicates whether two strings are equal.
Returns <see langword="true" /> if <paramref name="x" /> and <paramref name="y" /> refer to the same object, or <paramref name="x" /> and <paramref name="y" /> are equal, or <paramref name="x" /> and <paramref name="y" /> are <see langword="null" /> ; otherwise, <see langword="false" /> .
x A string to compare to <paramref name="y" /> .
y A string to compare to <paramref name="x" /> .
public static StringComparer
FromComparison​(StringComparison comparisonType)
Converts the specified <see cref="T:System.StringComparison" /> instance to a <see cref="T:System.StringComparer" /> instance.
Returns A <see cref="T:System.StringComparer" /> instance representing the equivalent value of the specified <see cref="T:System.StringComparison" /> instance.
comparisonType A string comparer instance to convert.
public int
GetHashCode​(object obj)
When overridden in a derived class, gets the hash code for the specified object.
Returns A 32-bit signed hash code calculated from the value of the <paramref name="obj" /> parameter.
obj An object.
public int
GetHashCode​(string obj)
When overridden in a derived class, gets the hash code for the specified string.
Returns A 32-bit signed hash code calculated from the value of the <paramref name="obj" /> parameter.
obj A string.
public static bool
IsWellKnownCultureAwareComparer​(IEqualityComparer<​string> comparer, CompareInfo& compareInfo, CompareOptions& compareOptions)
public static bool
IsWellKnownOrdinalComparer​(IEqualityComparer<​string> comparer, Boolean& ignoreCase)
public bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj The object to compare with the current object.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.