Changes the type of the given Object to the given Type.
Assembly: mscorlib (in mscorlib.dll)
public abstract Object ChangeType( Object value, Type type, CultureInfo culture )
- Type: System.Object
The object to change into a new Type.
- Type: System.Type
The new Type that value will become.
- Type: System.Globalization.CultureInfo
Note For example, this parameter is necessary to convert a String that represents 1000 to a Double value, because 1000 is represented differently by different cultures.
Return ValueType: System.Object
An object that contains the given value as the new type.
Reflection models the accessibility rules of the common type system. For example, if the caller is in the same assembly, the caller does not need special permissions for internal members. Otherwise, the caller needs ReflectionPermission. This is consistent with lookup of members that are protected, private, and so on.
The general principle is that ChangeType should perform only widening coercions, which never lose data. An example of a widening coercion is coercing a value that is a 32-bit signed integer to a value that is a 64-bit signed integer. This is distinguished from a narrowing coercion, which may lose data. An example of a narrowing coercion is coercing a 64-bit signed integer to a 32-bit signed integer.
The following table lists the coercions performed by the default ChangeType.
Its base type.
The interface it implements.
UInt16, UInt32, Int32, UInt64, Int64, Single, Double
Char, UInt16, Int16, UInt32, Int32, UInt64, Int64, Single, Double
Int16, Int32, Int64, Single, Double
UInt32, Int32, UInt64, Int64, Single, Double
Int32, Int64, Single, Double
UInt64, Int64, Single, Double
Int64, Single, Double
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.