Windows Dev Center

The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Nullable(Of T) Narrowing Conversion (Nullable(Of T) to T)

Defines an explicit conversion of a Nullable(Of T) instance to its underlying value.

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

Public Shared Narrowing Operator CType ( _
	value As Nullable(Of T) _
) As T


Type: System.Nullable(Of T)

A nullable value.

Return Value

Type: T
The value of the Value property for the value parameter.

This operator supports the explicit conversion of the current Nullable(Of T) instance to type T, the type of Value. The syntax for such explicit conversions is language-dependent. You may also be able to perform the conversion by calling the Convert.ChangeType method.

The Narrowing operator enables code such as the following, which converts a Nullable(Of Int32) value to an Int32 value.

Module Example
   Public Sub Main()
       Dim nullInt = New Nullable(Of Integer)(172)
       ' Convert with CInt conversion method.
       ' Convert with CType conversion method.
       Console.WriteLine(CType(nullInt, Integer))
       ' Convert with Convert.ChangeType.
       Console.WriteLine(Convert.ChangeType(nullInt, GetType(Integer)))
   End Sub 
End Module 
' The example displays the following output: 
'       172 
'       172 
'       172

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
© 2015 Microsoft