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

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

Nullable.GetUnderlyingType メソッド

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

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

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

例外例外
例外種類条件

ArgumentNullException

nullableTypenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

戻り値Int32Nullable 型であるメソッド定義するコード例次に示します。このコード例では、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

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



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

   

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



Nullable.GetUnderlyingType メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS