Convert.ChangeType Method (Object, Type)
Returns an object of the specified type and whose value is equivalent to the specified object.
Assembly: mscorlib (in mscorlib.dll)
The type of object to return.
Return ValueType: System.Object
An object whose type is conversionType and whose value is equivalent to value.
A null reference (Nothing in Visual Basic), if value is null and conversionType is not a value type.
This conversion is not supported.
value is null and conversionType is a value type.
value does not implement the IConvertible interface.
value is not in a format recognized by conversionType.
value represents a number that is out of the range of conversionType.
conversionType is null.
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.
Notes to Callers:
The Continent enumeration value.method can convert an enumeration value to another type. However, it cannot convert another type to an enumeration value, even if the source type is the underlying type of the enumeration. To convert a type to an enumeration value, use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a
The Nullable<'T>.To perform the conversion, you can use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a nullable type.method can convert a nullable type to another type. However, it cannot convert another type to a value of a nullable type, even if conversionType is the underlying type of the
Available since 4.5
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Available since 8.1