ChangeType Method (Object, Type)
Collapse the table of content
Expand the table of content

Convert.ChangeType Method (Object, Type)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Returns an object of the specified type and whose value is equivalent to the specified object.

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

'Declaration
Public Shared Function ChangeType ( _
	value As Object, _
	conversionType As Type _
) As Object

Parameters

value
Type: System.Object
An object that implements the IConvertible interface.
conversionType
Type: System.Type
The type of object to return.

Return Value

Type: System.Object
An object whose type is conversionType and whose value is equivalent to value.
-or-
A null reference (Nothing in Visual Basic), if value is Nothing and conversionType is not a value type.

ExceptionCondition
InvalidCastException

This conversion is not supported.

-or-

value is Nothing and conversionType is a value type.

-or-

value does not implement the IConvertible interface.

FormatException

value is not in a format recognized by conversionType.

OverflowException

value represents a number that is out of the range of conversionType.

ArgumentNullException

conversionType is Nothing.

ChangeType is a general-purpose conversion method that converts the object specified by value to conversionType. The value parameter can be an object of any type, and conversionType can also be a Type object that represents any base or custom type. For the conversion to succeed, value must implement the IConvertible interface, because the method simply wraps a call to an appropriate IConvertible method. The method requires that conversion of value to conversionType be supported.

This method uses the current thread's culture for the conversion.

The following example illustrates the use of the ChangeType method.

Windows Phone OS

Supported in: 8.1, 8.0

Show:
© 2017 Microsoft