StringExtensionsTryParse(String, Type, Object) Method

Tries to parse an object of type type from a string value. Firstly, it tries to parse the type natively. If type cannot be parsed natively but the type has a TypeConverter or a registered conversion that can convert from string, then the type converter or conversion will be used.
See the Remarks section of the ParseT(String, CultureInfo) method for details.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public static bool TryParse(
	this string? s,
	Type type,
	out Object?? value
)

Parameters

s  String
The string value to parse. If and type is a reference or nullable type, then value will be .
type  Type
The desired type of the returned value.
value  Object
When this method returns with result, then this parameter contains the result of the parsing. It can be even if s is and type is a reference or nullable type.

Return Value

Boolean
, if s could be parsed as type, which is returned in the value parameter; otherwise, .

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

ArgumentNullExceptiontype is null, or type is not nullable and s is .

See Also