public struct Char : IComparable, IComparable<Char>, IEquatable<Char>
Object
ValueType
CharThis type implements IComparable, System.IComparable<System.Char>, and System.IEquatable<System.Char>.
mscorlib
BCL
Represents a Unicode character.
The Char value type represents Unicode characters, with code points ranging from 0 to 65,535.[Note: The code point of a Unicode character is that character's 2-byte, encoded value.]
[Note: The UnicodeCategory enumeration describes the categories that a Unicode character can be mapped to. For information on mapping specific Unicode characters to Unicode categories, see the UnicodeData.txt file in the Unicode Character Database at http://www.unicode.org/Public/UNIDATA/UnicodeCharacterDatabase.html. The UnicodeData.txt file format is described at http://www.unicode.org/Public/3.1-Update/UnicodeData-3.1.0.html.]
System Namespace
Char Methods
Char.CompareTo(char) Method
Char.CompareTo(System.Object) Method
Char.Equals(char) Method
Char.Equals(System.Object) Method
Char.GetHashCode Method
Char.GetNumericValue(System.String, int) Method
Char.GetNumericValue(char) Method
Char.GetUnicodeCategory(System.String, int) Method
Char.GetUnicodeCategory(char) Method
Char.IsControl(System.String, int) Method
Char.IsControl(char) Method
Char.IsDigit(System.String, int) Method
Char.IsDigit(char) Method
Char.IsLetter(char) Method
Char.IsLetter(System.String, int) Method
Char.IsLetterOrDigit(char) Method
Char.IsLetterOrDigit(System.String, int) Method
Char.IsLower(char) Method
Char.IsLower(System.String, int) Method
Char.IsNumber(char) Method
Char.IsNumber(System.String, int) Method
Char.IsPunctuation(char) Method
Char.IsPunctuation(System.String, int) Method
Char.IsSeparator(System.String, int) Method
Char.IsSeparator(char) Method
Char.IsSurrogate(System.String, int) Method
Char.IsSurrogate(char) Method
Char.IsSymbol(char) Method
Char.IsSymbol(System.String, int) Method
Char.IsUpper(System.String, int) Method
Char.IsUpper(char) Method
Char.IsWhiteSpace(System.String, int) Method
Char.IsWhiteSpace(char) Method
Char.Parse Method
Char.ToLower Method
Char.ToString() Method
Char.ToString(System.IFormatProvider) Method
Char.ToUpper Method
Char Fields
public int CompareTo(char value);
Returns the sort order of the current instance compared to the specified Char .
- value
- The Char to compare to the current instance.
The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:
Return Value Description A negative number Current instance < value. Zero Current instance == value. A positive number Current instance > value.
The comparison performed by this method is based on the code points of the current instance and value, not necessarily their lexicographical characteristics.[Note: This method is implemented to support the System.IComparable<Char> interface.]
System.Char Structure, System Namespace
public int CompareTo(object value);
Returns the sort order of the current instance compared to the specified Object .
- value
- The Object to compare to the current instance.
The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:
Return Value Description A negative number Current instance < value. Zero Current instance == value. A positive number Current instance > value, or value is a null reference.
Exception Type Condition ArgumentException value is not a Char and is not a null reference.
The comparison performed by this method is based on the code points of the current instance and value, not necessarily their lexicographical characteristics.[Note: This method is implemented to support the IComparable interface.]
System.Char Structure, System Namespace
public override bool Equals(char obj);
Determines whether the current instance and the specified Char represent the same value.
- obj
- The Char to compare to the current instance.
true
if obj represents the same value as the current instance; otherwise,false
.
The comparison performed by this method is based on the code points of the current instance and obj, not necessarily their lexicographical characteristics.[Note: This method is implemented to support the System.IEquatable<Char> interface.]
System.Char Structure, System Namespace
public override bool Equals(object obj);
Determines whether the current instance and the specified Object represent the same type and value.
- obj
- The Object to compare to the current instance.
true
if obj represents the same type and value as the current instance. If obj is a null reference or is not an instance of Char, returnsfalse
.
The comparison performed by this method is based on the code points of the current instance and obj, not necessarily their lexicographical characteristics.[Note: This method overrides System.Object.Equals(System.Object).]
System.Char Structure, System Namespace
public override int GetHashCode();
Generates a hash code for the current instance.
A Int32 value containing a hash code for the current instance.
The algorithm used to generate the hash code is unspecified.[Note: This method overrides System.Object.GetHashCode.]
System.Char Structure, System Namespace
public static double GetNumericValue(string s, int index);
Returns the numeric value associated with the Unicode character at the specified position in the specified String.
- s
- A String.
- index
- A Int32 that specifies the position of a character in s.
A Double representing the numeric value associated with the Char at position index in s if and only if that Char has an associated numeric value; otherwise, -1.0.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
A character has an associated numeric value if and only if it is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.DecimalDigitNumber, System.Globalization.UnicodeCategory.LetterNumber, or System.Globalization.UnicodeCategory.OtherNumber .
ExtendedNumerics
System.Char Structure, System Namespace
public static double GetNumericValue(char c);
Returns the numeric value associated with the specified Unicode character.
- c
- A Unicode character.
A Double representing the numeric value associated with c if and only if c has an associated numeric value; otherwise, -1.0.
A character has an associated numeric value if and only if it is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.DecimalDigitNumber, System.Globalization.UnicodeCategory.LetterNumber, or System.Globalization.UnicodeCategory.OtherNumber.
The following example demonstrates the System.Char.GetNumericValue(System.Char) method.
using System; public class GetNumericValueExample { public static void Main() { Char[] cAry = {'8', 'V', Convert.ToChar(0X00BC)}; //Unicode U+00BC is the code point for the character //representation of 1/4 foreach(Char c in cAry) { Console.Write("Numeric value of Unicode " + "character {0} ", c); Console.WriteLine(" is {0}", Char.GetNumericValue(c)); } } }The output is
Numeric value of Unicode character 8 is 8
Numeric value of Unicode character V is -1
Numeric value of Unicode character is 0.25
ExtendedNumerics
System.Char Structure, System Namespace
public static UnicodeCategory GetUnicodeCategory(string s, int index);
Determines the UnicodeCategory of the character at the specified position in the specified String .
- s
- A String.
- index
- A Int32 that specifies the position of a character in s.
The UnicodeCategory of the Char at position index in s.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
[Note: For more information regarding Unicode categories, see UnicodeCategory.]
System.Char Structure, System Namespace
public static UnicodeCategory GetUnicodeCategory(char c);
Determines the UnicodeCategory of the specified Unicode character.
- c
- A Unicode character.
The UnicodeCategory of c.
[Note: For more information regarding Unicode categories, see UnicodeCategory.]
System.Char Structure, System Namespace
public static bool IsControl(string s, int index);
Determines whether the character at the specified position in the specified String is a control character.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.Control; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsControl(char c);
Determines whether the specified Unicode character is a control character.
- c
- A Unicode character.
true if c is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.Control; otherwise,false
.
System.Char Structure, System Namespace
public static bool IsDigit(string s, int index);
Determines whether the character at the specified position in the specified String is a decimal digit.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.DecimalDigitNumber; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
[Note: System.Char.IsDigit(System.Char) determines if a Char is a radix-10 digit. This contrasts with System.Char.IsNumber(System.Char), which determines if a Char is of any numeric Unicode category.]
System.Char Structure, System Namespace
public static bool IsDigit(char c);
Determines whether a Unicode character is a decimal digit.
- c
- A Unicode character.
true
if c is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.DecimalDigitNumber; otherwise,false
.
[Note: System.Char.IsDigit(System.Char) determines if a Char is a radix-10 digit. This contrasts with System.Char.IsNumber(System.Char), which determines if a Char is of any numeric Unicode category.]
System.Char Structure, System Namespace
public static bool IsLetter(char c);
Determines whether the specified Unicode character is a letter.
- c
- A Unicode character.
true
if c is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.UppercaseLetter, System.Globalization.UnicodeCategory.LowercaseLetter, System.Globalization.UnicodeCategory.TitlecaseLetter, System.Globalization.UnicodeCategory.ModifierLetter, or System.Globalization.UnicodeCategory.OtherLetter; otherwise,false
.
System.Char Structure, System Namespace
public static bool IsLetter(string s, int index);
Determines whether the character at the specified position in the specified String is a letter.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.UppercaseLetter, System.Globalization.UnicodeCategory.LowercaseLetter, System.Globalization.UnicodeCategory.TitlecaseLetter, System.Globalization.UnicodeCategory.ModifierLetter, or System.Globalization.UnicodeCategory.OtherLetter; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsLetterOrDigit(char c);
Determines whether the specified Unicode character is either a letter or a decimal digit.
- c
- A Unicode character.
true
if c is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.UppercaseLetter, System.Globalization.UnicodeCategory.LowercaseLetter, System.Globalization.UnicodeCategory.TitlecaseLetter, System.Globalization.UnicodeCategory.ModifierLetter, System.Globalization.UnicodeCategory.OtherLetter, or System.Globalization.UnicodeCategory.DecimalDigitNumber; otherwise,false
.
System.Char Structure, System Namespace
public static bool IsLetterOrDigit(string s, int index);
Determines whether the character at the specified position in the specified String is either a letter or a decimal digit.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.UppercaseLetter, System.Globalization.UnicodeCategory.LowercaseLetter, System.Globalization.UnicodeCategory.TitlecaseLetter, System.Globalization.UnicodeCategory.ModifierLetter, System.Globalization.UnicodeCategory.OtherLetter, or System.Globalization.UnicodeCategory.DecimalDigitNumber; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsLower(char c);
Determines whether the specified Unicode character is a lowercase letter.
- c
- A Unicode character.
true
if c is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.LowercaseLetter; otherwise,false
.
System.Char Structure, System Namespace
public static bool IsLower(string s, int index);
Determines whether the character at the specified position in the specified String is a lowercase letter.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of the following category in UnicodeCategory:System.Globalization.UnicodeCategory.LowercaseLetter; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsNumber(char c);
Determines whether the specified Unicode character is a number.
- c
- A Unicode character.
true
if c is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.DecimalDigitNumber, System.Globalization.UnicodeCategory.LetterNumber, or System.Globalization.UnicodeCategory.OtherNumber; otherwise,false
.
[Note: System.Char.IsNumber(System.Char) determines if a Char is of any numeric Unicode category. This contrasts with System.Char.IsDigit(System.Char), which determines if a Char is a radix-10 digit.]
System.Char Structure, System Namespace
public static bool IsNumber(string s, int index);
Determines whether the character at the specified position in the specified String is a number.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.DecimalDigitNumber, System.Globalization.UnicodeCategory.LetterNumber, or System.Globalization.UnicodeCategory.OtherNumber; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
[Note: System.Char.IsNumber(System.Char) determines if a Char is of any numeric Unicode category. This contrasts with System.Char.IsDigit(System.Char), which determines if a Char is a radix-10 digit.]
System.Char Structure, System Namespace
public static bool IsPunctuation(char c);
Determines whether the specified Unicode character is a punctuation mark.
- c
- A Unicode character.
true
if c is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.ConnectorPunctuation, System.Globalization.UnicodeCategory.DashPunctuation, System.Globalization.UnicodeCategory.OpenPunctuation, System.Globalization.UnicodeCategory.ClosePunctuation, System.Globalization.UnicodeCategory.InitialQuotePunctuation, System.Globalization.UnicodeCategory.FinalQuotePunctuation, or System.Globalization.UnicodeCategory.OtherPunctuation; otherwise,false
.
System.Char Structure, System Namespace
public static bool IsPunctuation(string s, int index);
Determines whether the character at the specified position in the specified String is a punctuation mark.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.ConnectorPunctuation, System.Globalization.UnicodeCategory.DashPunctuation, System.Globalization.UnicodeCategory.OpenPunctuation, System.Globalization.UnicodeCategory.ClosePunctuation, System.Globalization.UnicodeCategory.InitialQuotePunctuation, System.Globalization.UnicodeCategory.FinalQuotePunctuation, or System.Globalization.UnicodeCategory.OtherPunctuation; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsSeparator(string s, int index);
Determines whether the character at the specified position in the specified String is a separator character.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.SpaceSeparator, System.Globalization.UnicodeCategory.LineSeparator, or System.Globalization.UnicodeCategory.ParagraphSeparator; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsSeparator(char c);
Determines whether the specified Unicode character is a separator character.
- c
- A Unicode character.
true
if c is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.SpaceSeparator, System.Globalization.UnicodeCategory.LineSeparator, or System.Globalization.UnicodeCategory.ParagraphSeparator; otherwise,false
.
System.Char Structure, System Namespace
public static bool IsSurrogate(string s, int index);
Determines whether the character at the specified position in the specified String is a surrogate character.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.Surrogate; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsSurrogate(char c);
Determines whether the specified Unicode character is a surrogate character.
- c
- A Unicode character.
true
if c is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.Surrogate; otherwise,false
.
System.Char Structure, System Namespace
public static bool IsSymbol(char c);
Determines whether the specified Unicode character is a symbol character.
- c
- A Unicode character.
true
if c is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.MathSymbol, System.Globalization.UnicodeCategory.CurrencySymbol, System.Globalization.UnicodeCategory.ModifierSymbol, or System.Globalization.UnicodeCategory.OtherSymbol; otherwise,false
.
System.Char Structure, System Namespace
public static bool IsSymbol(string s, int index);
Determines whether the character at the specified position in the specified String is a symbol character.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of one of the following categories in UnicodeCategory: System.Globalization.UnicodeCategory.MathSymbol, System.Globalization.UnicodeCategory.CurrencySymbol, System.Globalization.UnicodeCategory.ModifierSymbol, or System.Globalization.UnicodeCategory.OtherSymbol; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsUpper(string s, int index);
Determines whether the character at the specified position in the specified String is an uppercase letter.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.UppercaseLetter; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference. ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsUpper(char c);
Determines whether the specified Unicode character is an uppercase letter.
- c
- A Unicode character.
true
if c is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.UppercaseLetter; otherwise,false
.
System.Char Structure, System Namespace
public static bool IsWhiteSpace(string s, int index);
Determines whether the character at the specified position in the specified String is a whitespace character.
- s
- A String.
- index
- A Int32 that specifies a character position in s.
true
if the character at position index in s either has a code point of 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x0085, 0x2028, or 0x2029; or is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.SpaceSeparator; otherwise,false
.
Exception Type Condition ArgumentNullException s is a null reference.
ArgumentOutOfRangeException The value of index is less than zero, or greater than or equal to the length of s.
System.Char Structure, System Namespace
public static bool IsWhiteSpace(char c);
Determines whether the specified Unicode character is a whitespace character.
- c
- A Unicode character.
true
if c either has a code point of 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x0085, 0x2028, or 0x2029; or is a member of the following category in UnicodeCategory: System.Globalization.UnicodeCategory.SpaceSeparator; otherwise,false
.
System.Char Structure, System Namespace
public static char Parse(string s);
Returns the specified String converted to a Char value.
- s
- A String containing a single Unicode character.
The Char value obtained from s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s does not contain exactly one character.
System.Char Structure, System Namespace
public static char ToLower(char c);
Converts a Char to its lowercase equivalent.
- c
- A Unicode character.
The lowercase equivalent of c, or the value of c if and only if c is already lowercase or does not have a lowercase equivalent.
The following example demonstrates the System.Char.ToLower(System.Char,System.Globalization.CultureInfo) method.
using System; public class CharToLower { public static void Main() { Char[] cAry = {'A', 'c', '*'}; foreach (Char c in cAry) { Console.Write("Char '{0}' ToLower is ", c); Console.WriteLine("{0}", Char.ToLower(c)); } } }The output is
Char 'A' ToLower is a
Char 'c' ToLower is c
Char '*' ToLower is *
System.Char Structure, System Namespace
public override string ToString();
Returns a String representation of the value of the current instance.
A String representation of the current instance.
[Note: This method overrides System.Object.ToString.]
System.Char Structure, System Namespace
public string ToString(IFormatProvider provider);
Converts the value of this instance to its equivalentString
representation using the specified culture-specific format information.
- provider
- (Reserved) An IFormatProvider interface implementation that supplies culture-specific formatting information.
The String representation of the value of this instance as specified by provider.
provider is ignored; it does not participate in this operation.
System.Char Structure, System Namespace
public static char ToUpper(char c);
Converts a Char to its uppercase equivalent.
- c
- A Unicode character.
The uppercase equivalent of c, or the value of c if and only if c is already uppercase or does not have an uppercase equivalent.
The following example demonstrates the System.Char.ToUpper(System.Char,System.Globalization.CultureInfo) method.
using System; public class CharToUpper { public static void Main() { Char[] cAry = {'A', 'c', '*'}; foreach (Char c in cAry) { Console.Write("Char '{0}' ToUpper is {1}", c, Char.ToUpper(c)); Console.WriteLine(); } } }The output is
Char 'A' ToUpper is A
Char 'c' ToUpper is C
Char '*' ToUpper is *
System.Char Structure, System Namespace
public const char MaxValue = (char)0xFFFF;
Contains the maximum code point for the Char type.
The numeric value of this constant is 65,535.
System.Char Structure, System Namespace
public const char MinValue = (char)0x0;
Contains the minimum code point for the Char type.
The numeric value of this constant is 0.
System.Char Structure, System Namespace