Char Struct

Definition

Represents a character as a UTF-16 code unit.

[ComVisible(true)]
[Serializable]
public struct Char : IComparable, IConvertible, IComparable<char>, IEquatable<char>

Inherited Members

System.Object

Fields

MaxValue

Represents the largest possible value of a Char. This field is constant.

public const char MaxValue = '\uffff'
See Also

MinValue

Represents the smallest possible value of a Char. This field is constant.

public const char MinValue = '\0'
See Also

Methods

CompareTo(Char)

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.

public int CompareTo(char value)
Parameters
value
Char

A Char object to compare.

Returns

A signed number indicating the position of this instance in the sort order in relation to the value parameter.

Return Value

Description

Less than zero

This instance precedes value.

Zero

This instance has the same position in the sort order as value.

Greater than zero

This instance follows value.

See Also

ConvertFromUtf32(Int32)

Converts the specified Unicode code point into a UTF-16 encoded string.

public static string ConvertFromUtf32(int utf32)
Parameters
utf32
Int32

A 21-bit Unicode code point.

Returns

A string consisting of one Char object or a surrogate pair of Char objects equivalent to the code point specified by the utf32 parameter.

Exceptions

utf32 is not a valid 21-bit Unicode code point ranging from U+0 through U+10FFFF, excluding the surrogate pair range from U+D800 through U+DFFF.

See Also

ConvertToUtf32(Char, Char)

Converts the value of a UTF-16 encoded surrogate pair into a Unicode code point.

public static int ConvertToUtf32(char highSurrogate, char lowSurrogate)
Parameters
highSurrogate
Char

A high surrogate code unit (that is, a code unit ranging from U+D800 through U+DBFF).

lowSurrogate
Char

A low surrogate code unit (that is, a code unit ranging from U+DC00 through U+DFFF).

Returns

The 21-bit Unicode code point represented by the highSurrogate and lowSurrogate parameters.

Exceptions

highSurrogate is not in the range U+D800 through U+DBFF, or lowSurrogate is not in the range U+DC00 through U+DFFF.

See Also

ConvertToUtf32(String, Int32)

Converts the value of a UTF-16 encoded character or surrogate pair at a specified position in a string into a Unicode code point.

public static int ConvertToUtf32(string s, int index)
Parameters
s
String

A string that contains a character or surrogate pair.

index
Int32

The index position of the character or surrogate pair in s.

Returns

The 21-bit Unicode code point represented by the character or surrogate pair at the position in the s parameter specified by the index parameter.

Exceptions

index is not a position within s.

The specified index position contains a surrogate pair, and either the first character in the pair is not a valid high surrogate or the second character in the pair is not a valid low surrogate.

See Also

Equals(Char)

Returns a value that indicates whether this instance is equal to the specified Char object.

public bool Equals(char obj)
Parameters
obj
Char

An object to compare to this instance.

Returns

true if the obj parameter equals the value of this instance; otherwise, false.

See Also

Equals(Object)

Returns a value that indicates whether this instance is equal to a specified object.

public override bool Equals(object obj)
Parameters
obj
Object

An object to compare with this instance or null.

Returns

true if obj is an instance of Char and equals the value of this instance; otherwise, false.

Overrides

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()
Returns

A 32-bit signed integer hash code.

Overrides

GetNumericValue(Char)

Converts the specified numeric Unicode character to a double-precision floating point number.

public static double GetNumericValue(char c)
Parameters
c
Char

The Unicode character to convert.

Returns

The numeric value of c if that character represents a number; otherwise, -1.0.

GetNumericValue(String, Int32)

Converts the numeric Unicode character at the specified position in a specified string to a double-precision floating point number.

public static double GetNumericValue(string s, int index)
Parameters
s
String

A String.

index
Int32

The character position in s.

Returns

The numeric value of the character at position index in s if that character represents a number; otherwise, -1.

Exceptions

index is less than zero or greater than the last position in s.

IsControl(Char)

Indicates whether the specified Unicode character is categorized as a control character.

public static bool IsControl(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is a control character; otherwise, false.

IsControl(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a control character.

public static bool IsControl(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a control character; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

IsDigit(Char)

Indicates whether the specified Unicode character is categorized as a decimal digit.

public static bool IsDigit(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is a decimal digit; otherwise, false.

See Also

IsDigit(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a decimal digit.

public static bool IsDigit(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a decimal digit; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsHighSurrogate(Char)

Indicates whether the specified Char object is a high surrogate.

public static bool IsHighSurrogate(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if the numeric value of the c parameter ranges from U+D800 through U+DBFF; otherwise, false.

IsHighSurrogate(String, Int32)

Indicates whether the Char object at the specified position in a string is a high surrogate.

public static bool IsHighSurrogate(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the numeric value of the specified character in the s parameter ranges from U+D800 through U+DBFF; otherwise, false.

Exceptions

index is not a position within s.

IsLetter(Char)

Indicates whether the specified Unicode character is categorized as a Unicode letter.

public static bool IsLetter(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is a letter; otherwise, false.

See Also

IsLetter(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a Unicode letter.

public static bool IsLetter(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a letter; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsLetterOrDigit(Char)

Indicates whether the specified Unicode character is categorized as a letter or a decimal digit.

public static bool IsLetterOrDigit(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is a letter or a decimal digit; otherwise, false.

See Also

IsLetterOrDigit(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a letter or a decimal digit.

public static bool IsLetterOrDigit(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a letter or a decimal digit; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsLower(Char)

Indicates whether the specified Unicode character is categorized as a lowercase letter.

public static bool IsLower(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is a lowercase letter; otherwise, false.

See Also

IsLower(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a lowercase letter.

public static bool IsLower(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a lowercase letter; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsLowSurrogate(Char)

Indicates whether the specified Char object is a low surrogate.

public static bool IsLowSurrogate(char c)
Parameters
c
Char

The character to evaluate.

Returns

true if the numeric value of the c parameter ranges from U+DC00 through U+DFFF; otherwise, false.

IsLowSurrogate(String, Int32)

Indicates whether the Char object at the specified position in a string is a low surrogate.

public static bool IsLowSurrogate(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the numeric value of the specified character in the s parameter ranges from U+DC00 through U+DFFF; otherwise, false.

Exceptions

index is not a position within s.

IsNumber(Char)

Indicates whether the specified Unicode character is categorized as a number.

public static bool IsNumber(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is a number; otherwise, false.

See Also

IsNumber(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a number.

public static bool IsNumber(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a number; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsPunctuation(Char)

Indicates whether the specified Unicode character is categorized as a punctuation mark.

public static bool IsPunctuation(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is a punctuation mark; otherwise, false.

See Also

IsPunctuation(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a punctuation mark.

public static bool IsPunctuation(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a punctuation mark; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsSeparator(Char)

Indicates whether the specified Unicode character is categorized as a separator character.

public static bool IsSeparator(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is a separator character; otherwise, false.

IsSeparator(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a separator character.

public static bool IsSeparator(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a separator character; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsSurrogate(Char)

Indicates whether the specified character has a surrogate code unit.

public static bool IsSurrogate(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is either a high surrogate or a low surrogate; otherwise, false.

See Also

IsSurrogate(String, Int32)

Indicates whether the character at the specified position in a specified string has a surrogate code unit.

public static bool IsSurrogate(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a either a high surrogate or a low surrogate; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsSurrogatePair(Char, Char)

Indicates whether the two specified Char objects form a surrogate pair.

public static bool IsSurrogatePair(char highSurrogate, char lowSurrogate)
Parameters
highSurrogate
Char

The character to evaluate as the high surrogate of a surrogate pair.

lowSurrogate
Char

The character to evaluate as the low surrogate of a surrogate pair.

Returns

true if the numeric value of the highSurrogate parameter ranges from U+D800 through U+DBFF, and the numeric value of the lowSurrogate parameter ranges from U+DC00 through U+DFFF; otherwise, false.

See Also

IsSurrogatePair(String, Int32)

Indicates whether two adjacent Char objects at a specified position in a string form a surrogate pair.

public static bool IsSurrogatePair(string s, int index)
Parameters
s
String

A string.

index
Int32

The starting position of the pair of characters to evaluate within s.

Returns

true if the s parameter includes adjacent characters at positions index and index + 1, and the numeric value of the character at position index ranges from U+D800 through U+DBFF, and the numeric value of the character at position index+1 ranges from U+DC00 through U+DFFF; otherwise, false.

Exceptions

index is not a position within s.

See Also

IsSymbol(Char)

Indicates whether the specified Unicode character is categorized as a symbol character.

public static bool IsSymbol(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is a symbol character; otherwise, false.

See Also

IsSymbol(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as a symbol character.

public static bool IsSymbol(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is a symbol character; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsUpper(Char)

Indicates whether the specified Unicode character is categorized as an uppercase letter.

public static bool IsUpper(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is an uppercase letter; otherwise, false.

See Also

IsUpper(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as an uppercase letter.

public static bool IsUpper(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is an uppercase letter; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

IsWhiteSpace(Char)

Indicates whether the specified Unicode character is categorized as white space.

public static bool IsWhiteSpace(char c)
Parameters
c
Char

The Unicode character to evaluate.

Returns

true if c is white space; otherwise, false.

See Also

IsWhiteSpace(String, Int32)

Indicates whether the character at the specified position in a specified string is categorized as white space.

public static bool IsWhiteSpace(string s, int index)
Parameters
s
String

A string.

index
Int32

The position of the character to evaluate in s.

Returns

true if the character at position index in s is white space; otherwise, false.

Exceptions

index is less than zero or greater than the last position in s.

See Also

Parse(String)

Converts the value of the specified string to its equivalent Unicode character.

public static char Parse(string s)
Parameters
s
String

A string that contains a single character, or null.

Returns

A Unicode character equivalent to the sole character in s.

Exceptions

The length of s is not 1.

See Also

ToLower(Char)

Converts the value of a Unicode character to its lowercase equivalent.

public static char ToLower(char c)
Parameters
c
Char

The Unicode character to convert.

Returns

The lowercase equivalent of c, or the unchanged value of c, if c is already lowercase or not alphabetic.

ToLowerInvariant(Char)

Converts the value of a Unicode character to its lowercase equivalent using the casing rules of the invariant culture.

public static char ToLowerInvariant(char c)
Parameters
c
Char

The Unicode character to convert.

Returns

The lowercase equivalent of the c parameter, or the unchanged value of c, if c is already lowercase or not alphabetic.

ToString()

Converts the value of this instance to its equivalent string representation.

public override string ToString()
Returns

The string representation of the value of this instance.

Overrides
See Also

ToString(Char)

Converts the specified Unicode character to its equivalent string representation.

public static string ToString(char c)
Parameters
c
Char

The Unicode character to convert.

Returns

The string representation of the value of c.

See Also

ToUpper(Char)

Converts the value of a Unicode character to its uppercase equivalent.

public static char ToUpper(char c)
Parameters
c
Char

The Unicode character to convert.

Returns

The uppercase equivalent of c, or the unchanged value of c if c is already uppercase, has no uppercase equivalent, or is not alphabetic.

ToUpperInvariant(Char)

Converts the value of a Unicode character to its uppercase equivalent using the casing rules of the invariant culture.

public static char ToUpperInvariant(char c)
Parameters
c
Char

The Unicode character to convert.

Returns

The uppercase equivalent of the c parameter, or the unchanged value of c, if c is already uppercase or not alphabetic.

TryParse(String, out Char)

Converts the value of the specified string to its equivalent Unicode character. A return code indicates whether the conversion succeeded or failed.

public static bool TryParse(string s, out char result)
Parameters
s
String

A string that contains a single character, or null.

result
Char

When this method returns, contains a Unicode character equivalent to the sole character in s, if the conversion succeeded, or an undefined value if the conversion failed. The conversion fails if the s parameter is null or the length of s is not 1. This parameter is passed uninitialized.

Returns

true if the s parameter was converted successfully; otherwise, false.

See Also

Explicit Interface Implementations

IComparable.CompareTo(Object)

int IComparable.CompareTo(object value)
Parameters
value
Object
Returns

IConvertible.GetTypeCode()

TypeCode IConvertible.GetTypeCode()
Returns

IConvertible.ToBoolean(IFormatProvider)

Note This conversion is not supported. Attempting to do so throws an InvalidCastException.

bool IConvertible.ToBoolean(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

This conversion is not supported. No value is returned.

Exceptions

This conversion is not supported.

IConvertible.ToByte(IFormatProvider)

For a description of this member, see ToByte(IFormatProvider).

byte IConvertible.ToByte(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

The converted value of the current Char object.

IConvertible.ToChar(IFormatProvider)

For a description of this member, see ToChar(IFormatProvider).

char IConvertible.ToChar(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

The value of the current Char object unchanged.

IConvertible.ToDateTime(IFormatProvider)

Note This conversion is not supported. Attempting to do so throws an InvalidCastException.

DateTime IConvertible.ToDateTime(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

No value is returned.

Exceptions

This conversion is not supported.

IConvertible.ToDecimal(IFormatProvider)

Note This conversion is not supported. Attempting to do so throws an InvalidCastException.

decimal IConvertible.ToDecimal(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

No value is returned.

Exceptions

This conversion is not supported.

IConvertible.ToDouble(IFormatProvider)

Note This conversion is not supported. Attempting to do so throws an InvalidCastException.

double IConvertible.ToDouble(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

No value is returned.

Exceptions

This conversion is not supported.

IConvertible.ToInt16(IFormatProvider)

For a description of this member, see ToInt16(IFormatProvider).

short IConvertible.ToInt16(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

The converted value of the current Char object.

IConvertible.ToInt32(IFormatProvider)

For a description of this member, see ToInt32(IFormatProvider).

int IConvertible.ToInt32(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

The converted value of the current Char object.

IConvertible.ToInt64(IFormatProvider)

For a description of this member, see ToInt64(IFormatProvider).

long IConvertible.ToInt64(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

The converted value of the current Char object.

IConvertible.ToSByte(IFormatProvider)

For a description of this member, see ToSByte(IFormatProvider).

sbyte IConvertible.ToSByte(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

The converted value of the current Char object.

IConvertible.ToSingle(IFormatProvider)

Note This conversion is not supported. Attempting to do so throws an InvalidCastException.

float IConvertible.ToSingle(IFormatProvider provider)
Parameters
provider
IFormatProvider

This parameter is ignored.

Returns

No value is returned.

Exceptions

This conversion is not supported.

IConvertible.ToString(IFormatProvider)

string IConvertible.ToString(IFormatProvider provider)
Parameters
provider
IFormatProvider
Returns

IConvertible.ToType(Type, IFormatProvider)

For a description of this member, see ToType(Type, IFormatProvider).

object IConvertible.ToType(Type type, IFormatProvider provider)
Parameters
type
Type

A Type object.

provider
IFormatProvider

An IFormatProvider object.

Returns

An object of the specified type.

Exceptions

type is null.

The value of the current Char object cannot be converted to the type specified by the type parameter.

IConvertible.ToUInt16(IFormatProvider)

For a description of this member, see ToUInt16(IFormatProvider).

ushort IConvertible.ToUInt16(IFormatProvider provider)
Parameters
provider
IFormatProvider

An IFormatProvider object. (Specify null because the provider parameter is ignored.)

Returns

The converted value of the current Char object.

IConvertible.ToUInt32(IFormatProvider)

For a description of this member, see ToUInt32(IFormatProvider).

uint IConvertible.ToUInt32(IFormatProvider provider)
Parameters
provider
IFormatProvider

An IFormatProvider object. (Specify null because the provider parameter is ignored.)

Returns

The converted value of the current Char object.

IConvertible.ToUInt64(IFormatProvider)

For a description of this member, see ToUInt64(IFormatProvider).

ulong IConvertible.ToUInt64(IFormatProvider provider)
Parameters
provider
IFormatProvider

An IFormatProvider object. (Specify null because the provider parameter is ignored.)

Returns

The converted value of the current Char object.

See Also