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.
Assembly: mscorlib (in mscorlib.dll)
static member ChangeType : value:Object * typeCode:TypeCode * provider:IFormatProvider -> Object
The type of object to return.
An object that supplies culture-specific formatting information.
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.
The ChangeType(Object, Type, IFormatProvider) method.method does not support the conversion of value to a custom type. To perform such a conversion, call the
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 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.
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 method. The example then creates an array with a Double and a DateTime value and makes repeated calls to 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.
Available since 10
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0