Export (0) Print
Expand All

Char.TryParse Method

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static function TryParse(
	s : String, 
	result : char
) : boolean

Parameters

s
Type: System.String

A string containing a single character or a null reference (Nothing in Visual Basic).

result
Type: System.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 a null reference (Nothing in Visual Basic) or the length of s is not 1. This parameter is passed uninitialized.

Return Value

Type: System.Boolean
true if the s parameter was converted successfully; otherwise, false.

The TryParse method is like the Parse method, except the TryParse method does not throw an exception if the conversion fails.

The following code example demonstrates overloads of the TryParse method for several base types, and the TryParseExact method for the DateTime base type.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft