Nullable<T>.Explicit(Nullable<T> to T) Opérateur

Définition

Définit une conversion explicite d’une instance Nullable<T> à sa valeur sous-jacente.

public:
 static explicit operator T(Nullable<T> value);
public static explicit operator T (T? value);
static member op_Explicit : Nullable<'T (requires 'T : struct)> -> 'T
Public Shared Narrowing Operator CType (value As Nullable(Of T)) As T

Paramètres

value
Nullable<T>

Valeur de type Nullable.

Retours

T

Valeur de la propriété Value pour le paramètre value.

Exemples

L’opérateur Explicit active le code tel que le suivant, qui convertit une Nullable(Of Int32) valeur en Int32 valeur.

using System;

public class Example
{
   public static void Main()
   {
       var nullInt = new Nullable<int>(172);
       // Convert with CInt conversion method.
       Console.WriteLine((int)nullInt);
       // Convert with Convert.ChangeType.
       Console.WriteLine(Convert.ChangeType(nullInt, typeof(int)));
   }
}
// The example displays the following output:
//       172
//       172
open System

let nullInt = Nullable 172
// Convert with int conversion function.
printfn $"{int nullInt}"
// Convert with Convert.ChangeType.
printfn $"{Convert.ChangeType(nullInt, typeof<int>)}"
// The example displays the following output:
//       172
//       172
Module Example
   Public Sub Main()
       Dim nullInt = New Nullable(Of Integer)(172)
       ' Convert with CInt conversion method.
       Console.WriteLine(CInt(nullInt))
       ' 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

Remarques

Cet opérateur prend en charge la conversion explicite de l’instance actuelle Nullable<T> en type T, le type de Value. La syntaxe de ces conversions explicites dépend du langage. Vous pouvez également effectuer la conversion en appelant la Convert.ChangeType méthode.

La méthode équivalente pour cet opérateur est Nullable<T>.Value

S’applique à