StringExtensionsParseT(String, CultureInfo) Method

Parses an object of type T from a string value. Firstly, it tries to parse the type natively. If T 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.


Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
public static T Parse<T>(
	this string? s,
	CultureInfo? culture = null


s  String
The string value to parse. If and T is a reference or nullable type, then the method returns .
culture  CultureInfo  (Optional)
The culture to use for the parsing. If , then the InvariantCulture will be used. This parameter is optional.
Default value: .

Type Parameters

The desired type of the return value.

Return Value

An instance of T, which is the result of the parsing. A reference can be returned if s is , and T is a reference or nullable type.

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).


New conversions can be registered by the RegisterConversion extension methods.

A TypeConverter can be registered by the RegisterTypeConverter extension method.

Natively parsed types:


ArgumentNullExceptionT is not nullable and s is .
ArgumentExceptionParameter s cannot be parsed as T.

See Also