Nullable.GetUnderlyingType メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Nullable.GetUnderlyingType メソッドの意味・解説 

Nullable.GetUnderlyingType メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

指定した NULL 許容型の基になる型を返します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function GetUnderlyingType
 ( _
    nullableType As Type _
) As Type
Dim nullableType As Type
Dim returnValue As Type

returnValue = Nullable.GetUnderlyingType(nullableType)
public static Type GetUnderlyingType (
    Type nullableType
)
public:
static Type^ GetUnderlyingType (
    Type^ nullableType
)
public static Type GetUnderlyingType (
    Type nullableType
)
public static function GetUnderlyingType
 (
    nullableType : Type
) : Type

パラメータ

nullableType

クローズ ジェネリック NULL 許容型を表す Type オブジェクト。

戻り値
nullableType パラメータがクローズ ジェネリック NULL 許容型の場合は nullableType パラメータの型引数。それ以外の場合は null 参照 (Visual Basic では Nothing)。

例外例外
例外の種類条件

ArgumentNullException

nullableType が null 参照 (Visual Basic では Nothing) です。

解説解説

ジェネリック型定義は、型パラメータ リストを含む Nullable のような型宣言であり、型パラメータ リストは 1 つ以上の型パラメータを宣言します。クローズ ジェネリック型は、型パラメータに特定の型が指定された型宣言です。

たとえば、nullableType パラメータが C# で Nullable<Int32> 型 (Visual Basic の場合は Nullable(Of Int32) 型) である場合、戻り値は、Int32 型 (クローズ ジェネリック型の型引数) です。

使用例使用例

戻り値が Int32 の Nullable 型であるメソッドを定義するコード例を次に示します。このコード例では、GetUnderlyingType メソッドを使用して、戻り値の型引数を表示します。

' This code example demonstrates the 
' Nullable.GetUnderlyingType() method.

Imports System
Imports System.Reflection

Class Sample
    ' Declare a type named Example. 
    ' The MyMethod member of Example returns a Nullable of Int32.
    
    Public Class Example
        Public Function MyMethod() As
 Nullable(Of Integer)
            Return 0
        End Function
    End Class 'Example
    
' 
'   Use reflection to obtain a Type object for the Example type.
'   Use the Type object to obtain a MethodInfo object for the MyMethod
 method.
'   Use the MethodInfo object to obtain the type of the return value
 of 
'     MyMethod, which is Nullable of Int32.
'   Use the GetUnderlyingType method to obtain the type argument of
 the 
'     return value type, which is Int32.
'
    Public Shared Sub Main()
 
        Dim t As Type = GetType(Example)
        Dim mi As MethodInfo = t.GetMethod("MyMethod")
        Dim retval As Type = mi.ReturnType
        Console.WriteLine("Return value type ... {0}",
 retval)
        Dim answer As Type = Nullable.GetUnderlyingType(retval)
        Console.WriteLine("Underlying type ..... {0}",
 answer)
    
    End Sub 'Main
End Class 'Sample
'
'This code example produces the following results:
'
'Return value type ... System.Nullable`1[System.Int32]
'Underlying type ..... System.Int32
'
// This code example demonstrates the 
// Nullable.GetUnderlyingType() method.

using System;
using System.Reflection;

class Sample 
{
// Declare a type named Example. 
// The MyMethod member of Example returns a Nullable of Int32.

    public class Example
    {
        public int? MyMethod() 
        {
        return 0;
        }
    }
    
/* 
   Use reflection to obtain a Type object for the Example type.
   Use the Type object to obtain a MethodInfo object for the MyMethod
 method.
   Use the MethodInfo object to obtain the type of the return
 value of 
     MyMethod, which is Nullable of Int32.
   Use the GetUnderlyingType method to obtain the type argument of the 
     return value type, which is Int32.
*/   
    public static void Main()
 
    {
        Type t = typeof(Example);
        MethodInfo mi = t.GetMethod("MyMethod");
        Type retval = mi.ReturnType;
        Console.WriteLine("Return value type ... {0}", retval);
        Type answer = Nullable.GetUnderlyingType(retval);
        Console.WriteLine("Underlying type ..... {0}", answer);
    }
}
/*
This code example produces the following results:

Return value type ... System.Nullable`1[System.Int32]
Underlying type ..... System.Int32

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

Nullable.GetUnderlyingType メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Nullable.GetUnderlyingType メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS