Nullable<T>.Explicit(Nullable<T> to T) 연산자

정의

인스턴스를 기본 값으로 Nullable<T> 명시적으로 변환하는 방법을 정의합니다.

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

매개 변수

value
Nullable<T>

nullable 값입니다.

반품

T

매개 변수의 Value 속성 값입니다 value .

예제

연산자는 Explicit 값을 값 Nullable(Of Int32) 으로 변환 Int32 하는 다음과 같은 코드를 사용하도록 설정합니다.

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

설명

이 연산자는 현재 Nullable<T> 인스턴스를 형식 T( 형식)으로 명시적으로 변환하는 것을 지원합니다 Value. 이러한 명시적 변환에 대한 구문은 언어에 따라 다릅니다. 메서드를 호출 Convert.ChangeType 하여 변환을 수행할 수도 있습니다.

이 연산자에 해당하는 메서드는 다음과 같습니다. Nullable<T>.Value

적용 대상