Nullable<T>.Explicit(Nullable<T> to T) Operator
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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>
null 許容値。
返品
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