This documentation is archived and is not being maintained.

8.9 Narrowing Conversions

Visual Studio .NET 2003

Narrowing conversions are conversions that cannot be proved to always succeed, conversions that are known to possibly lose information, and conversions across domains of types sufficiently different to merit narrowing notation. The following conversions are classified as narrowing conversions:

  • Conversions from any type to a more derived type.
  • Numeric type conversions in the following direction: Double, Single, Decimal, Long, Integer, Short, Byte.
  • Conversions from Boolean to any numeric type.
  • Conversions from any numeric type to Boolean.
  • Conversions from any numeric type to any enumerated type.
  • Conversions from any enumerated type to any type its underlying type has a narrowing conversion to.
  • Conversions from any enumerated type to any other enumerated type.
  • Conversions from any class type to any interface type, provided the class type does not implement the interface type.
  • Conversions from any interface type to any class type.
  • Conversions from any interface type to any value type that implements the interface type.
  • Conversions from any interface type to any other interface type, provided there is no inheritance relationship between the two types.
  • Conversions from an array type S with an element type SE, to a covariant-array type T with an element type TE, provided that all of the following are true:
    • S and T differ only in element type.
    • Both SE and TE are reference types.
    • A narrowing reference conversion exists from SE to TE.
  • Conversions from String to Char.
  • Conversions from String to Char().
  • Conversions from String to Boolean and from Boolean to String.
  • Conversions between String and Byte, Short, Integer, Long, Decimal, Single, or Double.
  • Conversions from String to Date and from Date to String.

See Also

8.3 Numeric Conversions | 8.4 Reference Conversions | 8.6 Value Type Conversions | 8.5 Array Covariance | 8.8 Widening Conversions | 8. Conversions | Conversion Summary (Visual Basic Language Reference) | Widening and Narrowing Conversions (Visual Basic Language Concepts)

Show: