StringExtensionsParse(String, Type, CultureInfo) Method

Parses an object 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) overload for details.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 7.1.0
C#
public static Object? Parse(
	this string? s,
	Type type,
	CultureInfo? culture = null
)

Parameters

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

Return Value

Object
An object of type, which is the result of the parsing.

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 , or type is not nullable and s is .
ArgumentExceptionParameter s cannot be parsed as type.

See Also