C# Char TryParse
Description
Char TryParse
converts the value of the specified string
to its equivalent Unicode character. A return code indicates whether the
conversion succeeded or failed.
Syntax
Char.TryParse
has the following syntax.
public static bool TryParse(
string s,
out char result
)
Parameters
Char.TryParse
has the following parameters.
s
- A string that contains a single character, or null.result
- 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
Char.TryParse
method returns true if the s parameter was converted successfully; otherwise, false.
Example
The following code example demonstrates overloads of the TryParse method for several base types, and the TryParseExact method for the DateTime base type.
/* w w w.j a v a2 s . c om*/
using System;
using System.Globalization;
class Sample
{
public static void Main()
{
bool result;
Char charVal;
result = Char.TryParse("A", out charVal);
Console.WriteLine(result);
Console.WriteLine(charVal.ToString());
}
}
The code above generates the following result.