Nullable<T>.Explicit(Nullable<T> to T) Operatör

Tanım

Bir örneğin temel alınan değerine açık bir Nullable<T> dönüşümünü tanımlar.

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

Parametreler

value
Nullable<T>

Null değer atanabilir bir değer.

Döndürülenler

T

parametresi için Value özelliğinin value değeri.

Örnekler

Explicit işleci aşağıdaki gibi bir değeri bir Nullable(Of Int32) değere Int32 dönüştüren kodu etkinleştirir.

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

Açıklamalar

Bu işleç, geçerli Nullable<T> örneğin türü olan türüne Taçık dönüştürmesini Valuedestekler. Bu tür açık dönüştürmelerin söz dizimi dile bağlıdır. Dönüştürme işlemini yöntemini çağırarak Convert.ChangeType da gerçekleştirebilirsiniz.

Bu işlecin eşdeğer yöntemi şudur: Nullable<T>.Value

Şunlara uygulanır