Nullable<T>.Explicit(Nullable<T> to T) Operátor

Definice

Definuje explicitní převod Nullable<T> instance na její podkladovou hodnotu.

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

Parametry

value
Nullable<T>

Hodnota s možnou hodnotou null.

Návraty

T

Hodnota Value vlastnosti parametru value .

Příklady

Operátor Explicit povolí kód, například následující, který převede Nullable(Of Int32) hodnotu na Int32 hodnotu.

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

Poznámky

Tento operátor podporuje explicitní převod aktuální Nullable<T> instance na typ T, typ .Value Syntaxe takových explicitních převodů je závislá na jazyce. Převod můžete provést také voláním Convert.ChangeType metody.

Ekvivalentní metoda tohoto operátoru je Nullable<T>.Value

Platí pro