mscorlib(4.0.0.0) API with additions
System.StringComparer Class Referenceabstract

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

Inheritance diagram for System.StringComparer:
[legend]
Collaboration diagram for System.StringComparer:
[legend]

Public Member Functions

int Compare (object x, object y)
 When overridden in a derived class, compares two objects and returns an indication of their relative sort order. More...
 
new bool Equals (object x, object y)
 When overridden in a derived class, indicates whether two objects are equal. More...
 
int GetHashCode (object obj)
 When overridden in a derived class, gets the hash code for the specified object. More...
 
abstract int Compare (string x, string y)
 When overridden in a derived class, compares two strings and returns an indication of their relative sort order. More...
 
abstract bool Equals (string x, string y)
 When overridden in a derived class, indicates whether two strings are equal. More...
 
abstract int GetHashCode (string obj)
 When overridden in a derived class, gets the hash code for the specified string. More...
 
- Public Member Functions inherited from System.Collections.IComparer< string >
int Compare (object x, object y)
 Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. More...
 
- Public Member Functions inherited from System.Collections.Generic.IEqualityComparer< string >
bool Equals (T x, T y)
 Determines whether the specified objects are equal. More...
 
int GetHashCode (T obj)
 Returns a hash code for the specified object. More...
 

Static Public Member Functions

static StringComparer Create (CultureInfo culture, bool ignoreCase)
 Creates a T:System.StringComparer object that compares strings according to the rules of a specified culture. More...
 

Static Public Attributes

static StringComparer InvariantCulture => _invariantCulture
 Gets a T:System.StringComparer object that performs a case-sensitive string comparison using the word comparison rules of the invariant culture. More...
 
static StringComparer InvariantCultureIgnoreCase => _invariantCultureIgnoreCase
 Gets a T:System.StringComparer object that performs a case-insensitive string comparison using the word comparison rules of the invariant culture. More...
 

Protected Member Functions

 StringComparer ()
 Initializes a new instance of the T:System.StringComparer class. More...
 

Properties

static StringComparer CurrentCulture [get]
 Gets a T:System.StringComparer object that performs a case-sensitive string comparison using the word comparison rules of the current culture. More...
 
static StringComparer CurrentCultureIgnoreCase [get]
 Gets a T:System.StringComparer object that performs case-insensitive string comparisons using the word comparison rules of the current culture. More...
 
static StringComparer Ordinal [get]
 Gets a T:System.StringComparer object that performs a case-sensitive ordinal string comparison. More...
 
static StringComparer OrdinalIgnoreCase [get]
 Gets a T:System.StringComparer object that performs a case-insensitive ordinal string comparison. More...
 

Detailed Description

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

Definition at line 12 of file StringComparer.cs.

Constructor & Destructor Documentation

◆ StringComparer()

System.StringComparer.StringComparer ( )
protected

Initializes a new instance of the T:System.StringComparer class.

Definition at line 216 of file StringComparer.cs.

Member Function Documentation

◆ Compare() [1/2]

int System.StringComparer.Compare ( object  x,
object  y 
)

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

Parameters
xAn object to compare to y .
yAn object to compare to x .
Returns
A signed integer that indicates the relative values of x and y , as shown in the following table.ValueMeaningLess than zero x precedes y in the sort order. -or- x is null and y is not null.Zero x is equal to y .-or- x and y are both null. Greater than zero x follows y in the sort order.-or- y is null and x is not null.
Exceptions
T:System.ArgumentExceptionNeither x nor y is a T:System.String object, and neither x nor y implements the T:System.IComparable interface.

Implements System.Collections.IComparer.

Definition at line 106 of file StringComparer.cs.

◆ Compare() [2/2]

abstract int System.StringComparer.Compare ( string  x,
string  y 
)
pure virtual

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

Parameters
xA string to compare to y .
yA string to compare to x .
Returns
A signed integer that indicates the relative values of x and y , as shown in the following table.ValueMeaningLess than zero x precedes y in the sort order.-or- x is null and y is not null.Zero x is equal to y .-or- x and y are both null. Greater than zero x follows y in the sort order.-or- y is null and x is not null.

◆ Create()

static StringComparer System.StringComparer.Create ( CultureInfo  culture,
bool  ignoreCase 
)
static

Creates a T:System.StringComparer object that compares strings according to the rules of a specified culture.

Parameters
cultureA culture whose linguistic rules are used to perform a string comparison.
ignoreCasetrue to specify that comparison operations be case-insensitive; false to specify that comparison operations be case-sensitive.
Returns
A new T:System.StringComparer object that performs string comparisons according to the comparison rules used by the culture parameter and the case rule specified by the ignoreCase parameter.
Exceptions
T:System.ArgumentNullExceptionculture is null.

Definition at line 86 of file StringComparer.cs.

◆ Equals() [1/2]

new bool System.StringComparer.Equals ( object  x,
object  y 
)

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

Parameters
xAn object to compare to y .
yAn object to compare to x .
Returns
true if x and y refer to the same object, or x and y are both the same type of object and those objects are equal, or both x and y are null; otherwise, false.

Implements System.Collections.IEqualityComparer.

Definition at line 142 of file StringComparer.cs.

◆ Equals() [2/2]

abstract bool System.StringComparer.Equals ( string  x,
string  y 
)
pure virtual

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

Parameters
xA string to compare to y .
yA string to compare to x .
Returns
true if x and y refer to the same object, or x and y are equal, or x and y are null; otherwise, false.

◆ GetHashCode() [1/2]

int System.StringComparer.GetHashCode ( object  obj)

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

Parameters
objAn object.
Returns
A 32-bit signed hash code calculated from the value of the obj parameter.
Exceptions
T:System.ArgumentExceptionNot enough memory is available to allocate the buffer that is required to compute the hash code.
T:System.ArgumentNullExceptionobj is null.

Implements System.Collections.IEqualityComparer.

Definition at line 170 of file StringComparer.cs.

◆ GetHashCode() [2/2]

abstract int System.StringComparer.GetHashCode ( string  obj)
pure virtual

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

Parameters
objA string.
Returns
A 32-bit signed hash code calculated from the value of the obj parameter.
Exceptions
T:System.ArgumentExceptionNot enough memory is available to allocate the buffer that is required to compute the hash code.
T:System.ArgumentNullExceptionobj is null.

Member Data Documentation

◆ InvariantCulture

StringComparer System.StringComparer.InvariantCulture => _invariantCulture
static

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

Returns
A new T:System.StringComparer object.

Definition at line 24 of file StringComparer.cs.

◆ InvariantCultureIgnoreCase

StringComparer System.StringComparer.InvariantCultureIgnoreCase => _invariantCultureIgnoreCase
static

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

Returns
A new T:System.StringComparer object.

Definition at line 28 of file StringComparer.cs.

Property Documentation

◆ CurrentCulture

StringComparer System.StringComparer.CurrentCulture
staticget

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

Returns
A new T:System.StringComparer object.

Definition at line 34 of file StringComparer.cs.

◆ CurrentCultureIgnoreCase

StringComparer System.StringComparer.CurrentCultureIgnoreCase
staticget

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

Returns
A new T:System.StringComparer object.

Definition at line 46 of file StringComparer.cs.

◆ Ordinal

StringComparer System.StringComparer.Ordinal
staticget

Gets a T:System.StringComparer object that performs a case-sensitive ordinal string comparison.

Returns
A T:System.StringComparer object.

Definition at line 58 of file StringComparer.cs.

◆ OrdinalIgnoreCase

StringComparer System.StringComparer.OrdinalIgnoreCase
staticget

Gets a T:System.StringComparer object that performs a case-insensitive ordinal string comparison.

Returns
A T:System.StringComparer object.

Definition at line 70 of file StringComparer.cs.


The documentation for this class was generated from the following file: