System.Char Structure

Assembly: Mscorlib.dll
Namespace: System
Summary
Represents a Unicode character.
C# Syntax:
[Serializable]
public struct Char : IComparable, IConvertible
Thread Safety
This type is safe for multithreaded operations.
Remarks
The Char value type represents Unicode characters with values ranging from hexadecimal 0x0000 to 0xFFFF.

Char provides methods to compare instances of this type, convert the value of an instance to its string representation, convert the string representation of a number to an instance of this type, and determine whether an instance is in a category such as digit, letter, punctuation, control character, and so on.

For information about how format specification codes control the string representation of value types, see the conceptual topic at MSDN: formattingoverview.

For more information about Unicode, see the Unicode Standard at http://www.unicode.org.

This type implements interfaces IComparable and IConvertible. Use the Convert class for conversions instead of this type's explicit interface member implementation of IConvertible.

Example
The following sample demonstrates some of the methods in Char.
using System;

public class CharStructureSample {
	public static void Main() {
		char chA = 'A';
		char ch1 = '1';
		string str = "test string"; 

		Console.WriteLine(chA.CompareTo('B'));			// Output: "-1" (meaning 'A' is 1 less than 'B')
		Console.WriteLine(chA.Equals('A'));				// Output: "True"
		Console.WriteLine(Char.GetNumericValue(ch1));	// Output: "1"
		Console.WriteLine(Char.IsControl('\t'));		// Output: "True"
		Console.WriteLine(Char.IsDigit(ch1));			// Output: "True"
		Console.WriteLine(Char.IsLetter(','));			// Output: "False"
		Console.WriteLine(Char.IsLower('u'));			// Output: "True"
		Console.WriteLine(Char.IsNumber(ch1));			// Output: "True"
		Console.WriteLine(Char.IsPunctuation('.'));		// Output: "True"
		Console.WriteLine(Char.IsSeparator(str, 4));	// Output: "True"
		Console.WriteLine(Char.IsSymbol('+'));			// Output: "True"
		Console.WriteLine(Char.IsWhiteSpace(str, 4));	// Output: "True"
		Console.WriteLine(Char.Parse("S"));				// Output: "S"
		Console.WriteLine(Char.ToLower('M'));			// Output: "m"
		Console.WriteLine('x'.ToString());				// Output: "x"
	}
}

    
See also:
System Namespace | IComparable | IConvertible | String

System.Char Member List:

Public Fields
MaxValue Represents the largest possible value of a Char. This field is constant.
MinValue Represents the smallest possible value of a Char. This field is constant.
Public Methods
CompareTo Compares this instance to a specified object and returns an indication of their relative values.
Equals Overridden:
Returns a value indicating whether this instance is equal to a specified object.
GetHashCode Overridden:
Returns the hash code for this instance.
GetNumericValue Overloaded:
GetNumericValue(char c)

Converts the specified numeric Unicode character to a double-precision floating point number.
GetNumericValue Overloaded:
GetNumericValue(string s, int index)

Converts the numeric Unicode character at the specified position in a specified string to a double-precision floating point number.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
GetTypeCode Returns the TypeCode for value type Char.
GetUnicodeCategory Overloaded:
GetUnicodeCategory(char c)

Categorizes a specified Unicode character into a group identified by one of the UnicodeCategory values.
GetUnicodeCategory Overloaded:
GetUnicodeCategory(string s, int index)

Categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values.
IsControl Overloaded:
IsControl(char c)

Indicates whether the specified Unicode character is categorized as a control character.
IsControl Overloaded:
IsControl(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as a control character.
IsDigit Overloaded:
IsDigit(char c)

Indicates whether the specified Unicode character is categorized as a decimal digit.
IsDigit Overloaded:
IsDigit(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as a decimal digit.
IsLetter Overloaded:
IsLetter(char c)

Indicates whether the specified Unicode character is categorized as an alphabetic letter.
IsLetter Overloaded:
IsLetter(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as an alphabetic character.
IsLetterOrDigit Overloaded:
IsLetterOrDigit(char c)

Indicates whether the specified Unicode character is categorized as an alphabetic letter or a decimal digit.
IsLetterOrDigit Overloaded:
IsLetterOrDigit(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as an alphabetic character or a decimal digit.
IsLower Overloaded:
IsLower(char c)

Indicates whether the specified Unicode character is categorized as a lowercase letter.
IsLower Overloaded:
IsLower(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as a lowercase letter.
IsNumber Overloaded:
IsNumber(char c)

Indicates whether the specified Unicode character is categorized as a decimal digit or hexadecimal number.
IsNumber Overloaded:
IsNumber(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as a decimal digit or hexadecimal number.
IsPunctuation Overloaded:
IsPunctuation(char c)

Indicates whether the specified Unicode character is categorized as a punctuation mark.
IsPunctuation Overloaded:
IsPunctuation(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as a punctuation mark.
IsSeparator Overloaded:
IsSeparator(char c)

Indicates whether the specified Unicode character is categorized as a separator character.
IsSeparator Overloaded:
IsSeparator(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as a separator character.
IsSurrogate Overloaded:
IsSurrogate(char c)

Indicates whether the specified Unicode character is categorized as a surrogate character.
IsSurrogate Overloaded:
IsSurrogate(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as a surrogate character.
IsSymbol Overloaded:
IsSymbol(char c)

Indicates whether the specified Unicode character is categorized as a symbol character.
IsSymbol Overloaded:
IsSymbol(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as a symbol character.
IsUpper Overloaded:
IsUpper(char c)

Indicates whether the specified Unicode character is categorized as an uppercase letter.
IsUpper Overloaded:
IsUpper(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as an uppercase letter.
IsWhiteSpace Overloaded:
IsWhiteSpace(char c)

Indicates whether the specified Unicode character is categorized as white space.
IsWhiteSpace Overloaded:
IsWhiteSpace(string s, int index)

Indicates whether the character at the specified position in a specified string is categorized as white space.
Parse Converts the value of the specified string to its equivalent Unicode character.
ToLower Overloaded:
ToLower(char c)

Converts the value of a Unicode character to its lowercase equivalent.
ToLower Overloaded:
ToLower(char c, CultureInfo culture)

Converts the value of a specified Unicode character to its lowercase equivalent using specified culture-specific formatting information.
ToString Overloaded:
ToString()

Overridden:
Converts the value of this instance to its equivalent string representation.
ToString Overloaded:
ToString(char c)

Converts the specified Unicode character to its equivalent string representation.
ToString Overloaded:
ToString(IFormatProvider provider)

Converts the value of this instance to its equivalent string representation using the specified culture-specific format information.
ToUpper Overloaded:
ToUpper(char c)

Converts the value of a Unicode character to its uppercase equivalent.
ToUpper Overloaded:
ToUpper(char c, CultureInfo culture)

Converts the value of a specified Unicode character to its uppercase equivalent using specified culture-specific formatting information.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Char Member Details

Field: MaxValue
Summary
Represents the largest possible value of a Char. This field is constant.
C# Syntax:
public const char MaxValue;
Remarks
The value of this constant is hexadecimal 0xFFFF.
See also:
Char.MinValue

Return to top


Field: MinValue
Summary
Represents the smallest possible value of a Char. This field is constant.
C# Syntax:
public const char MinValue;
Remarks
The value of this constant is hexadecimal 0x00.
See also:
Char.MaxValue

Return to top


Method: CompareTo(
   object value
)
Summary
Compares this instance to a specified object and returns an indication of their relative values.
C# Syntax:
public int CompareTo(
   object value
);
Parameters:

value

An object to compare, or null.

Return Value:
A signed number indicating the relative values of this instance and value.

Return Value Description
Less than zero This instance is less than .
Zero This instance is equal to .
Greater than zero This instance is greater than value. -or- value is null.
Exceptions
Exception Type Condition
ArgumentException value is not a Char or null.
Remarks
Any instance of Char, regardless of its value, is considered greater than null.

value must be null or an instance of Char; otherwise, an exception is thrown.

The comparison performed by this method is based on the encoded values of this instance and value, not necessarily their lexicographical characteristics.

This method is implemented to support the IComparable interface.

Example
The following sample demonstrates Char.CompareTo.
using System;

public class CompareToSample {
	public static void Main() {
		char chA = 'A';
		char chB = 'B';

		Console.WriteLine(chA.CompareTo('A'));	// Output: "0" (meaning they're equal)
		Console.WriteLine('b'.CompareTo(chB));	// Output: "32" (meaning 'b' is greater than 'B' by 32)
		Console.WriteLine(chA.CompareTo(chB));	// Output: "-1" (meaning 'A' is less than 'B' by 1)
	}
}

    
See also:
IComparable | Char.Equals

Return to top


Overridden Method: Equals(
   object obj
)
Summary
Returns a value indicating whether this instance is equal to a specified object.
C# Syntax:
public override bool Equals(
   object obj
);
Parameters:

obj

An object to compare with this instance or null.

Return Value:
true if obj is an instance of Char and equals the value of this instance; otherwise, false.
Remarks
The comparison performed by this method is based on the encoded values of this instance and obj, not necessarily their lexicographical characteristics.
Example
The following sample demonstrates Char.Equals.
using System;

public class EqualsSample {
	public static void Main() {
		char chA = 'A';
		char chB = 'B';

		Console.WriteLine(chA.Equals('A'));		// Output: "True"
		Console.WriteLine('b'.Equals(chB));		// Output: "False"
	}
}

    
See also:
Char.CompareTo

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Char();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: GetHashCode()
Summary
Returns the hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.

Return to top


Overloaded Method: GetNumericValue(
   char c
)
Summary
Converts the specified numeric Unicode character to a double-precision floating point number.
C# Syntax:
public static double GetNumericValue(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
The numeric value of c if that character represents a number; otherwise, -1.0.
Remarks
For example, if c is '5', the return value is 5. However, if c is 'z', the return value is -1.

A character has an associated numeric value if and only if it is a member of one of the following categories in UnicodeCategory: DecimalDigitNumber, LetterNumber, or OtherNumber.

Example
The following sample demonstrates Char.GetNumericValue.
using System;

public class GetNumericValueSample {
	public static void Main() {
		string str = "input: 1";

		Console.WriteLine(Char.GetNumericValue('8'));		// Output: "8"
		Console.WriteLine(Char.GetNumericValue(str, 8));	// Output: "1"
	}
}

    

Return to top


Overloaded Method: GetNumericValue(
   string s,
   int index
)
Summary
Converts the numeric Unicode character at the specified position in a specified string to a double-precision floating point number.
C# Syntax:
public static double GetNumericValue(
   string s,
   int index
);
Parameters:

s

A String.

index

The character position in s.

Return Value:
The numeric value of the character at position index in s if that character represents a number; otherwise, -1.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
For example, if the character at position index in s is '5', the return value is 5. However, if the character at position index in s is 'z', the return value is -1.

Character positions in a string are indexed starting from zero.

A character has an associated numeric value if and only if it is a member of one of the following categories in UnicodeCategory: DecimalDigitNumber, LetterNumber, or OtherNumber.

Example
The following sample demonstrates Char.GetNumericValue.
using System;

public class GetNumericValueSample {
	public static void Main() {
		string str = "input: 1";

		Console.WriteLine(Char.GetNumericValue('8'));		// Output: "8"
		Console.WriteLine(Char.GetNumericValue(str, 8));	// Output: "1"
	}
}

    

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetTypeCode()
Summary
Returns the TypeCode for value type Char.
C# Syntax:
public TypeCode GetTypeCode();
Return Value:
The enumerated constant, TypeCode.Char.

Return to top


Overloaded Method: GetUnicodeCategory(
   char c
)
Summary
Categorizes a specified Unicode character into a group identified by one of the UnicodeCategory values.
C# Syntax:
public static UnicodeCategory GetUnicodeCategory(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
A UnicodeCategory value that identifies the group that contains c.
Example
The following sample demonstrates Char.GetUnicodeCategory.

Return to top


Overloaded Method: GetUnicodeCategory(
   string s,
   int index
)
Summary
Categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values.
C# Syntax:
public static UnicodeCategory GetUnicodeCategory(
   string s,
   int index
);
Parameters:

s

A String.

index

The character position in s.

Return Value:
A UnicodeCategory enumerated constant that identifies the group that contains the character at position index in s.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.
Example
The following sample demonstrates Char.GetUnicodeCategory.

Return to top


Overloaded Method: IsControl(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as a control character.
C# Syntax:
public static bool IsControl(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is a control character; otherwise, false.
Remarks
Valid control characters are members of the following category in UnicodeCategory: Control.
Example
The following sample demonstrates Char.IsControl.
using System;

public class IsControlSample {
	public static void Main() {
		string str = "sample string";

		Console.WriteLine(Char.IsControl('\t'));	// Output: "True"
		Console.WriteLine(Char.IsControl(str, 7));	// Output: "False"
	}
}

    

Return to top


Overloaded Method: IsControl(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as a control character.
C# Syntax:
public static bool IsControl(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is a control character; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid control characters are members of the following category in UnicodeCategory: Control.

Example
The following sample demonstrates Char.IsControl.
using System;

public class IsControlSample {
	public static void Main() {
		string str = "sample string";

		Console.WriteLine(Char.IsControl('\t'));	// Output: "True"
		Console.WriteLine(Char.IsControl(str, 7));	// Output: "False"
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsDigit(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as a decimal digit.
C# Syntax:
public static bool IsDigit(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is a decimal digit; otherwise, false.
Remarks
This method determines if a Char is a radix-10 digit. This contrasts with Char.IsNumber which determines if a Char is of any numeric Unicode category.

Valid digits are members of the following category in UnicodeCategory: DecimalDigitNumber.

Example
The following sample demonstrates Char.IsDigit.
using System;

public class IsDigitSample {
	public static void Main() {
		char ch = '8';

		Console.WriteLine(Char.IsDigit(ch));					// Output: "True"
		Console.WriteLine(Char.IsDigit("sample string", 7));	// Output: "False"
	}
}

    
See also:
Boolean | Char.IsNumber

Return to top


Overloaded Method: IsDigit(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as a decimal digit.
C# Syntax:
public static bool IsDigit(
   string s,
   int index
);
Parameters:

s

A String.

index

The character position in s.

Return Value:
true if the character at position index in s is a decimal digit; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
This method determines if a Char is a radix-10 digit. This contrasts with Char.IsNumber, which determines if a Char is of any numeric Unicode category.

Character positions in a string are indexed starting from zero.

Valid digits are members of the following category in UnicodeCategory: DecimalDigitNumber.

Example
The following sample demonstrates Char.IsDigit.
using System;

public class IsDigitSample {
	public static void Main() {
		char ch = '8';

		Console.WriteLine(Char.IsDigit(ch));					// Output: "True"
		Console.WriteLine(Char.IsDigit("sample string", 7));	// Output: "False"
	}
}

    
See also:
Boolean | Char.IsNumber

Return to top


Overloaded Method: IsLetter(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as an alphabetic letter.
C# Syntax:
public static bool IsLetter(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is an alphabetic letter; otherwise, false.
Remarks
Valid letters are members of the following categories in UnicodeCategory: UppercaseLetter, LowercaseLetter, TitlecaseLetter, ModifierLetter, and OtherLetter.
Example
The following sample demonstrates Char.IsLetter.
using System;

public class IsLetterSample {
	public static void Main() {
		char ch = '8';

		Console.WriteLine(Char.IsLetter(ch));					// False
		Console.WriteLine(Char.IsLetter("sample string", 7));	// True
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsLetter(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as an alphabetic character.
C# Syntax:
public static bool IsLetter(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is an alphabetic character; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid letters are members of the following categories in UnicodeCategory: UppercaseLetter, LowercaseLetter, TitlecaseLetter, ModifierLetter, and OtherLetter.

Example
The following sample demonstrates Char.IsLetter.
using System;

public class IsLetterSample {
	public static void Main() {
		char ch = '8';

		Console.WriteLine(Char.IsLetter(ch));					// False
		Console.WriteLine(Char.IsLetter("sample string", 7));	// True
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsLetterOrDigit(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as an alphabetic letter or a decimal digit.
C# Syntax:
public static bool IsLetterOrDigit(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is an alphabetic letter or a decimal digit; otherwise, false.
Remarks
Valid alphabetic letters and decimal digits are members of the following categories in UnicodeCategory: UppercaseLetter, LowercaseLetter, TitlecaseLetter, ModifierLetter, OtherLetter, or DecimalDigitNumber.
Example
The following sample demonstrates Char.IsLetterOrDigit.
using System;

public class IsLetterOrDigitSample {
	public static void Main() {
		string str = "newline:\n";

		Console.WriteLine(Char.IsLetterOrDigit('8'));		// Output: "True"
		Console.WriteLine(Char.IsLetterOrDigit(str, 8));	// Output: "False", because it's a newline
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsLetterOrDigit(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as an alphabetic character or a decimal digit.
C# Syntax:
public static bool IsLetterOrDigit(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is an alphabetic character or a decimal digit; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid alphabetic letters and decimal digits are members of the following categories in UnicodeCategory: UppercaseLetter, LowercaseLetter, TitlecaseLetter, ModifierLetter, OtherLetter, or DecimalDigitNumber.

Example
The following sample demonstrates Char.IsLetterOrDigit.
using System;

public class IsLetterOrDigitSample {
	public static void Main() {
		string str = "newline:\n";

		Console.WriteLine(Char.IsLetterOrDigit('8'));		// Output: "True"
		Console.WriteLine(Char.IsLetterOrDigit(str, 8));	// Output: "False", because it's a newline
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsLower(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as a lowercase letter.
C# Syntax:
public static bool IsLower(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is a lowercase letter; otherwise, false.
Remarks
Valid lowercase letters are members of the following category in UnicodeCategory: LowercaseLetter.
Example
The following sample demonstrates Char.IsLower.
using System;

public class IsLowerSample {
	public static void Main() {
		char ch = 'a';

		Console.WriteLine(Char.IsLower(ch));				// Output: "True"
		Console.WriteLine(Char.IsLower("upperCase", 5));	// Output: "False"
	}
}

    
See also:
Boolean | Char.IsUpper

Return to top


Overloaded Method: IsLower(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as a lowercase letter.
C# Syntax:
public static bool IsLower(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is a lowercase letter; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid lowercase letters are members of the following category in UnicodeCategory: LowercaseLetter.

Example
The following sample demonstrates Char.IsLower.
using System;

public class IsLowerSample {
	public static void Main() {
		char ch = 'a';

		Console.WriteLine(Char.IsLower(ch));				// Output: "True"
		Console.WriteLine(Char.IsLower("upperCase", 5));	// Output: "False"
	}
}

    
See also:
Boolean | String | Char.IsUpper

Return to top


Overloaded Method: IsNumber(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as a decimal digit or hexadecimal number.
C# Syntax:
public static bool IsNumber(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is a decimal digit or hexadecimal number; otherwise, false.
Remarks
This method determines if a Char is of any numeric Unicode category. This contrasts with Char.IsDigit, which determines if a Char is a radix-10 digit.

Valid numbers are members of the following categories in UnicodeCategory: DecimalDigitNumber, LetterNumber, or OtherNumber.

Example
The following sample demonstrates Char.IsNumber.
using System;

public class IsNumberSample {
	public static void Main() {
		string str = "non-numeric";

		Console.WriteLine(Char.IsNumber('8'));		// Output: "True"
		Console.WriteLine(Char.IsNumber(str, 3));	// Output: "False"
	}
}

    
See also:
Boolean | Char.IsDigit

Return to top


Overloaded Method: IsNumber(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as a decimal digit or hexadecimal number.
C# Syntax:
public static bool IsNumber(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is a decimal digit or hexadecimal number; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
This method determines if a Char is of any numeric Unicode category. This contrasts with Char.IsDigit, which determines if a Char is a radix-10 digit.

Character positions in a string are indexed starting from zero.

Valid numbers are members of the following categories in UnicodeCategory: DecimalDigitNumber, LetterNumber, or OtherNumber.

Example
The following sample demonstrates Char.IsNumber.
using System;

public class IsNumberSample {
	public static void Main() {
		string str = "non-numeric";

		Console.WriteLine(Char.IsNumber('8'));		// Output: "True"
		Console.WriteLine(Char.IsNumber(str, 3));	// Output: "False"
	}
}

    
See also:
Boolean | String | Char.IsDigit

Return to top


Overloaded Method: IsPunctuation(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as a punctuation mark.
C# Syntax:
public static bool IsPunctuation(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is a punctuation mark; otherwise, false.
Remarks
Valid punctuation marks are members of the following categories in UnicodeCategory: ConnectorPunctuation, DashPunctuation, OpenPunctuation, ClosePunctuation, InititalQuotePunctuation, FinalQuotePunctuation, or OtherPunctuation.
Example
The following sample demonstrates Char.IsPunctuation.
using System;

public class IsPunctuationSample {
	public static void Main() {
		char ch = '.';

		Console.WriteLine(Char.IsPunctuation(ch));						// Output: "True"
		Console.WriteLine(Char.IsPunctuation("no punctuation", 3));		// Output: "False"
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsPunctuation(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as a punctuation mark.
C# Syntax:
public static bool IsPunctuation(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is a punctuation mark; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid punctuation marks are members of the following categories in UnicodeCategory: ConnectorPunctuation, DashPunctuation, OpenPunctuation, ClosePunctuation, InititalQuotePunctuation, FinalQuotePunctuation, or OtherPunctuation.

Example
The following sample demonstrates Char.IsPunctuation.
using System;

public class IsPunctuationSample {
	public static void Main() {
		char ch = '.';

		Console.WriteLine(Char.IsPunctuation(ch));						// Output: "True"
		Console.WriteLine(Char.IsPunctuation("no punctuation", 3));		// Output: "False"
	}
}

    
See also:
Boolean | String

Return to top


Overloaded Method: IsSeparator(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as a separator character.
C# Syntax:
public static bool IsSeparator(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is a separator character; otherwise, false.
Remarks
Valid separator characters are members of the following categories in UnicodeCategory: SpaceSeparator, LineSeparator, or ParagraphSeparator.
Example
The following sample demonstrates Char.IsSeparator.
using System;

public class IsSeparatorSample {
	public static void Main() {
		string str = "twain1 twain2";

		Console.WriteLine(Char.IsSeparator('a'));		// Output: "False"
		Console.WriteLine(Char.IsSeparator(str, 6));	// Output: "True"
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsSeparator(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as a separator character.
C# Syntax:
public static bool IsSeparator(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is a separator character; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid separator characters are members of the following categories in UnicodeCategory: SpaceSeparator, LineSeparator, or ParagraphSeparator.

Example
The following sample demonstrates Char.IsSeparator.
using System;

public class IsSeparatorSample {
	public static void Main() {
		string str = "twain1 twain2";

		Console.WriteLine(Char.IsSeparator('a'));		// Output: "False"
		Console.WriteLine(Char.IsSeparator(str, 6));	// Output: "True"
	}
}

    
See also:
Boolean | String

Return to top


Overloaded Method: IsSurrogate(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as a surrogate character.
C# Syntax:
public static bool IsSurrogate(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is a surrogate character; otherwise, false.
Remarks
Valid surrogate characters are members of the following category in UnicodeCategory: Surrogate.

For more information about surrogate pairs, see the Unicode Standard at http://www.unicode.org.

Example
The following sample demonstrates Char.IsSurrogate.
using System;

public class IsSurrogateSample {
	public static void Main() {
		string str = "\U00010F00"; // Unicode values between 0x10000 and 0x10FFF are represented by two 16-bit "surrogate" characters

		Console.WriteLine(Char.IsSurrogate('a'));		// Output: "False"
		Console.WriteLine(Char.IsSurrogate(str, 0));	// Output: "True"
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsSurrogate(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as a surrogate character.
C# Syntax:
public static bool IsSurrogate(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is a surrogate character; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid surrogate characters are members of the following category in UnicodeCategory: Surrogate.

For more information about surrogate pairs, see the Unicode Standard at http://www.unicode.org.

Example
The following sample demonstrates Char.IsSurrogate.
using System;

public class IsSurrogateSample {
	public static void Main() {
		string str = "\U00010F00"; // Unicode values between 0x10000 and 0x10FFF are represented by two 16-bit "surrogate" characters

		Console.WriteLine(Char.IsSurrogate('a'));		// Output: "False"
		Console.WriteLine(Char.IsSurrogate(str, 0));	// Output: "True"
	}
}

    
See also:
Boolean | String

Return to top


Overloaded Method: IsSymbol(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as a symbol character.
C# Syntax:
public static bool IsSymbol(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is a symbol character; otherwise, false.
Remarks
Valid symbols are members of the following categories in UnicodeCategory: MathSymbol, CurrencySymbol, ModifierSymbol, and OtherSymbol.
Example
The following sample demonstrates Char.IsSymbol.
using System;

public class IsSymbolSample {
	public static void Main() {
		string str = "non-symbolic characters"; 

		Console.WriteLine(Char.IsSymbol('+'));		// Output: "True"
		Console.WriteLine(Char.IsSymbol(str, 8));	// Output: "False"
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsSymbol(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as a symbol character.
C# Syntax:
public static bool IsSymbol(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is a symbol character; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid symbols are members of the following categories in UnicodeCategory: MathSymbol, CurrencySymbol, ModifierSymbol, and OtherSymbol.

Example
The following sample demonstrates Char.IsSymbol.
using System;

public class IsSymbolSample {
	public static void Main() {
		string str = "non-symbolic characters"; 

		Console.WriteLine(Char.IsSymbol('+'));		// Output: "True"
		Console.WriteLine(Char.IsSymbol(str, 8));	// Output: "False"
	}
}

    
See also:
Boolean | String

Return to top


Overloaded Method: IsUpper(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as an uppercase letter.
C# Syntax:
public static bool IsUpper(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is an uppercase letter; otherwise, false.
Remarks
Valid uppercase letters are members of the following category in UnicodeCategory: UppercaseLetter.
See also:
Boolean | Char.IsLower

Return to top


Overloaded Method: IsUpper(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as an uppercase letter.
C# Syntax:
public static bool IsUpper(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is an uppercase letter; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid uppercase letters are members of the following category in UnicodeCategory: UppercaseLetter.

See also:
Boolean | String

Return to top


Overloaded Method: IsWhiteSpace(
   char c
)
Summary
Indicates whether the specified Unicode character is categorized as white space.
C# Syntax:
public static bool IsWhiteSpace(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
true if c is white space; otherwise, false.
Remarks
Valid white space characters are members of the SpaceSeparator category in UnicodeCategory, as well as these Unicode characters: hexadecimal 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x0085, 0x2028, and 0x2029.
Example
The following sample demonstrates Char.IsWhiteSpace.
using System;

public class IsWhiteSpaceSample {
	public static void Main() {
		string str = "black matter"; 

		Console.WriteLine(Char.IsWhiteSpace('A'));		// Output: "False"
		Console.WriteLine(Char.IsWhiteSpace(str, 5));	// Output: "True"
	}
}

    
See also:
Boolean

Return to top


Overloaded Method: IsWhiteSpace(
   string s,
   int index
)
Summary
Indicates whether the character at the specified position in a specified string is categorized as white space.
C# Syntax:
public static bool IsWhiteSpace(
   string s,
   int index
);
Parameters:

s

A string.

index

The character position in s.

Return Value:
true if the character at position index in s is white space; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.
Remarks
Character positions in a string are indexed starting from zero.

Valid white space characters are members of the SpaceSeparator category in UnicodeCategory, as well as these Unicode characters: hexadecimal 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x0085, 0x2028, and 0x2029.

Example
The following sample demonstrates Char.IsWhiteSpace.
using System;

public class IsWhiteSpaceSample {
	public static void Main() {
		string str = "black matter"; 

		Console.WriteLine(Char.IsWhiteSpace('A'));		// Output: "False"
		Console.WriteLine(Char.IsWhiteSpace(str, 5));	// Output: "True"
	}
}

    
See also:
Boolean | String

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Parse(
   string s
)
Summary
Converts the value of the specified string to its equivalent Unicode character.
C# Syntax:
public static char Parse(
   string s
);
Parameters:

s

A string containinga single character or null.

Return Value:
A Unicode character equivalent to the sole character in s.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
FormatException s contains more than one character.
Example
The following sample demonstrates Char.Parse.
using System;

public class ParseSample {
	public static void Main() {
		Console.WriteLine(Char.Parse("A")); // Output: 'A'
	}
}

    
See also:
Char.ToString

Return to top


Overloaded Method: ToLower(
   char c
)
Summary
Converts the value of a Unicode character to its lowercase equivalent.
C# Syntax:
public static char ToLower(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
The lowercase equivalent of c.

-or-

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

Remarks
Formatting information is obtained from the current culture.

Use String.ToLower to convert a string to lowercase.

Example
The following sample demonstrates Char.ToLower.
using System;
using System.Globalization;  // for CultureInfo

public class ToLowerSample {
	public static void Main() {
		Console.WriteLine(Char.ToLower('A'));				// Output: "a"
	}
}

    
See also:
String.ToLower | Char.ToUpper

Return to top


Overloaded Method: ToLower(
   char c,
   CultureInfo culture
)
Summary
Converts the value of a specified Unicode character to its lowercase equivalent using specified culture-specific formatting information.
C# Syntax:
public static char ToLower(
   char c,
   CultureInfo culture
);
Parameters:

c

A Unicode character.

culture

A CultureInfo object that supplies culture-specific formatting information, or null.

Return Value:
The lowercase equivalent of c, formatted according to culture.

-or-

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

Exceptions
Exception Type Condition
ArgumentNullException culture is null.
Remarks
Use String.ToLower to convert a string to lowercase.
Example
The following sample demonstrates Char.ToLower.
using System;
using System.Globalization;  // for CultureInfo

public class ToLowerSample {
	public static void Main() {
		Console.WriteLine(Char.ToLower('A'));				// Output: "a"
	}
}

    
See also:
CultureInfo.CurrentCulture | String.ToLower | Char.ToUpper

Return to top


Overloaded Method: ToString()
Summary
Converts the value of this instance to its equivalent string representation.
C# Syntax:
public override string ToString();
Return Value:
The string representation of the value of this instance.
Example
The following sample demonstrates Char.ToString.
using System;

public class ToStringSample {
	public static void Main() {
		char ch = 'a';
		Console.WriteLine(ch.ToString());		// Output: "a"

		Console.WriteLine(Char.ToString('b'));	// Output: "b"
	}
}

    
See also:
MSDN: formattingoverview | Char.Parse | String

Return to top


Overloaded Method: ToString(
   char c
)
Summary
Converts the specified Unicode character to its equivalent string representation.
C# Syntax:
public static string ToString(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
The string representation of the value of c.
Example
The following sample demonstrates Char.ToString.
using System;

public class ToStringSample {
	public static void Main() {
		char ch = 'a';
		Console.WriteLine(ch.ToString());		// Output: "a"

		Console.WriteLine(Char.ToString('b'));	// Output: "b"
	}
}

    
See also:
Char.Parse | String

Return to top


Overloaded Method: ToString(
   IFormatProvider provider
)
Summary
Converts the value of this instance to its equivalent string representation using the specified culture-specific format information.
C# Syntax:
public string ToString(
   IFormatProvider provider
);
Parameters:

provider

(Reserved) An IFormatProvider that supplies culture-specific formatting information.

Return Value:
The string representation of the value of this instance as specified by provider.
Remarks
The provider parameter is ignored; it does not participate in this operation.
Example
The following sample demonstrates an overload of Char.ToString.
using System;

public class ToStringSample {
	public static void Main() {
		char ch = 'a';
		Console.WriteLine(ch.ToString());		// Output: "a"

		Console.WriteLine(Char.ToString('b'));	// Output: "b"
	}
}

    
See also:
Char.Parse | String

Return to top


Overloaded Method: ToUpper(
   char c
)
Summary
Converts the value of a Unicode character to its uppercase equivalent.
C# Syntax:
public static char ToUpper(
   char c
);
Parameters:

c

A Unicode character.

Return Value:
The uppercase equivalent of c.

-or-

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

Remarks
Formatting information is obtained from the current culture.

Use String.ToUpper to convert a string to uppercase.

See also:
String.ToUpper | Char.ToLower

Return to top


Overloaded Method: ToUpper(
   char c,
   CultureInfo culture
)
Summary
Converts the value of a specified Unicode character to its uppercase equivalent using specified culture-specific formatting information.
C# Syntax:
public static char ToUpper(
   char c,
   CultureInfo culture
);
Parameters:

c

A Unicode character.

culture

A CultureInfo object that supplies culture-specific formatting information, or null.

Return Value:
The uppercase equivalent of c, formatted according to culture.

-or-

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

Exceptions
Exception Type Condition
ArgumentNullException culture is null.
Remarks
Use String.ToUpper to convert a string to uppercase.
See also:
CultureInfo.CurrentCulture | String.ToUpper | Char.ToLower

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.