Sie sind auf Seite 1von 5

Character Methods |9 Character Methods 1.

CompareTo(Char) Description: Compares this instance to a specified object or value type, and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified object or value type. This member is overloaded. For complete information about this member, including syntax, usage, and examples, clicks a name in the overload list.

Overload List: Name CompareTo(Char) Description Compares this instance to a specified Char object and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified Char object.

CompareTo(Object) Compares this instance to a specified object and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified Object. Table 1.1 Overload List of CompareTo(Char) Return Value: Type: System.Int32 A signed number indicating the position of this instance in the sort order in relation to the value parameter.

C h a r a c t e r M e t h o d s | 10 Return Value Less than zero Zero Greater than zero Description This instance precedes value. This instance has the same position in the sort order as value. This instance follows value. Table 1.2 Return Value of CompareTo(Char)

Remarks: This method implements the System.IComparable(Of T) interface and performs slightly better than theChar.CompareTo method because it does not have to convert the value parameter to an object. The comparison performed by this method is based on the encoded values of this instance and value, not their lexicographical characteristics. If the CompareTo method parameter type has fewer bits (is narrower) than the instance type, some programming languages perform an implicit widening conversion that transforms the value of the parameter into a value with more bits. For example, suppose the instance type is Int32 and the parameter type is Byte. The Microsoft C# compiler generates instructions to represent the value of the parameter as an Int32 object, then generates a Int32.CompareTo method that compares the values of the Int32 instance and the Int32 parameter representation. Typically, implicit widening conversions are performed on numeric types. Consult your programming language's documentation to determine if its compiler performs widening conversions. If the instance and parameter types mismatch and a suitable conversion are not available, the compiler generates instructions to box the parameter and invoke the CompareTo overload that takes an Object parameter.

C h a r a c t e r M e t h o d s | 11 Example:

Example 1.1. Code of CompareTo(Char)

Example 1.2. Output 2. Equals(Char) Description: Returns a value that indicates whether this instance is equal to a specified object or Char value.

C h a r a c t e r M e t h o d s | 12 This member is overloaded. For complete information about this member, including syntax, usage, and examples, clicks a name in the overload list. Overload List: Name Equals(Char) Description Returns a value that indicates whether this instance is equal to the specified Charobject.

Equals(Object) Returns a value that indicates whether this instance is equal to a specified object.(Overrides ValueType.Equals(Object).) Table 2.1 Overload List of Equals() Return Value: Type: System.Boolean true if the obj parameter equals the value of this instance; otherwise, false. Remarks: This method implements the System.IEquatable(Of T) interface, and performs slightly better than Char.Equals because it does not need to unbox the obj parameter. Example:

Example 2.1. Code of Equals()

C h a r a c t e r M e t h o d s | 13

Example 2.2. Output 3. GetHashCode()

Das könnte Ihnen auch gefallen