Convert.ChangeType Method (Object, TypeCode, IFormatProvider)


Returns an object of the specified type whose value is equivalent to the specified object. A parameter supplies culture-specific formatting information.

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

static member ChangeType : 
        value:Object *
        typeCode:TypeCode *
        provider:IFormatProvider -> Object


Type: System.Object

An object that implements the IConvertible interface.

Type: System.TypeCode

The type of object to return.

Type: System.IFormatProvider

An object that supplies culture-specific formatting information.

Return Value

Type: System.Object

An object whose underlying type is typeCode and whose value is equivalent to value.


A null reference (Nothing in Visual Basic), if value is null and typeCode is Empty, String, or Object.

Exception Condition

This conversion is not supported.


value is null and typeCode specifies a value type.


value does not implement the IConvertible interface.


value is not in a format for the typeCode type recognized by provider.


value represents a number that is out of the range of the typeCode type.


typeCode is invalid.

ChangeType(Object, TypeCode, IFormatProvider) is a general-purpose conversion method that converts the object specified by value to a predefined type specified by typeCode. The value parameter can be an object of any 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 also requires that conversion of value to typeCode be supported.

The ChangeType(Object, TypeCode, IFormatProvider) method does not support the conversion of value to a custom type. To perform such a conversion, call the ChangeType(Object, Type, IFormatProvider) method.

The provider parameter is an IFormatProvider implementation that supplies formatting information for the conversion. Whether and how this parameter is used depends on the underlying IConvertible implementation. If value is a base data type, provider is used only for the following conversions. If a nullIFormatProvider argument is passed to these methods, the CultureInfo object that represents the current thread culture is used.

  • Conversion from a number to a string, or from a string to a number. provider must be a CultureInfo object, a NumberFormatInfo object, or a custom IFormatProvider implementation that returns a NumberFormatInfo object. However, because the ChangeType(Object, TypeCode, IFormatProvider) method performs the conversion using the default "G" format specifier, the provider parameter has no effect if value or the target type is an unsigned integer.

  • Conversion from a DateTime value to a string, or from a string to a DateTime value. provider must be a CultureInfo or DateTimeFormatInfo object.

If value is an application-defined type, its IConvertible implementation may use the provider parameter.

The following example defines a custom format provider named InterceptProvider that indicates when its GetFormat method is called and returns a NumberFormatInfo for the fr-FR culture and a DateTimeFormatInfo object for the en-US culture. This format provider is used in all calls to the ChangeType(Object, TypeCode, IFormatProvider) method. The example then creates an array with a Double and a DateTime value and makes repeated calls to ChangeType(Object, TypeCode, IFormatProvider) with each value and each member of the TypeCode enumeration. The example illustrates when the method uses the IFormatProvider parameter and also illustrates the use of the provider parameter to perform culture-sensitive formatting.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top