Compartir a través de


Binder.ChangeType Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Changes the type of the given Object to the given Type.

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

Syntax

'Declaration
Public MustOverride Function ChangeType ( _
    value As Object, _
    type As Type, _
    culture As CultureInfo _
) As Object
public abstract Object ChangeType(
    Object value,
    Type type,
    CultureInfo culture
)

Parameters

  • value
    Type: System.Object
    The object to change into a new Type.
  • type
    Type: System.Type
    The new Type that value will become.
  • culture
    Type: System.Globalization.CultureInfo
    An instance of CultureInfo that is used to control the coercion of data types. If culture is nulla null reference (Nothing in Visual Basic), the CultureInfo for the current thread is used.
    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 Value

Type: System.Object
An object that contains the given value as the new type.

Remarks

Reflection models the accessibility rules of the common type system. For example, if the caller is in the same assembly, the caller can access internal members. 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.

Source type

Target type

Any type

Its base type.

Any type

The interface it implements.

Char

UInt16, UInt32, Int32, UInt64, Int64, Single, Double

Byte

Char, UInt16, Int16, UInt32, Int32, UInt64, Int64, Single, Double

SByte

Int16, Int32, Int64, Single, Double

UInt16

UInt32, Int32, UInt64, Int64, Single, Double

Int16

Int32, Int64, Single, Double

UInt32

UInt64, Int64, Single, Double

Int32

Int64, Single, Double

UInt64

Single, Double

Int64

Single, Double

Single

Double

Non-reference

By-reference.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.