Nullable.GetUnderlyingType(Type) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 nullable 형식의 내부 형식 인수를 반환합니다.
public:
static Type ^ GetUnderlyingType(Type ^ nullableType);
public static Type GetUnderlyingType (Type nullableType);
public static Type? GetUnderlyingType (Type nullableType);
static member GetUnderlyingType : Type -> Type
Public Shared Function GetUnderlyingType (nullableType As Type) As Type
매개 변수
반환
nullableType
매개 변수가 폐쇄형 제네릭 nullable 형식이면 nullableType
매개 변수의 형식 인수이고, 그렇지 않으면 null
입니다.
예외
nullableType
이(가) null
인 경우
예제
다음 코드 예제에서는 반환 값이 형식 Nullable<T> 인 메서드를 정의합니다 Int32. 이 코드 예제에서는 메서드를 GetUnderlyingType 사용하여 반환 값의 형식 인수를 표시합니다.
// 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
*/
// This code example demonstrates the
// Nullable.GetUnderlyingType() method.
open System
// Declare a type named Example.
// The MyMethod member of Example returns a Nullable of Int32.
type Example() =
member _.MyMethod() =
Nullable 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.
*)
let t = typeof<Example>
let mi = t.GetMethod "MyMethod"
let retval = mi.ReturnType
printfn $"Return value type ... {retval}"
let answer = Nullable.GetUnderlyingType retval
printfn $"Underlying type ..... {answer}"
// 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.
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
'
' 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
End Class
'
'This code example produces the following results:
'
'Return value type ... System.Nullable`1[System.Int32]
'Underlying type ..... System.Int32
'
설명
제네릭 형식 정의는 형식 매개 변수 목록을 포함하는 와 같은 Nullable<T>형식 선언이며 형식 매개 변수 목록은 하나 이상의 형식 매개 변수를 선언합니다. 닫힌 제네릭 형식은 형식 매개 변수에 대해 특정 형식이 지정된 형식 선언입니다.
예를 들어 매개 변수가 nullableType
C#의 Nullable<Int32>
형식(Nullable(Of Int32)
Visual Basic의 경우)인 경우 반환 값은 형식 Int32 (즉, 닫힌 제네릭 형식의 형식 인수)입니다.
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기