Type.GetElementType Type.GetElementType Type.GetElementType Type.GetElementType Method

정의

파생 클래스에서 재정의되면, 현재 배열, 포인터 또는 참조 형식에 의해 포함되거나 참조되는 개체의 Type을 반환합니다.When overridden in a derived class, returns the Type of the object encompassed or referred to by the current array, pointer or reference type.

public:
 abstract Type ^ GetElementType();
public abstract Type GetElementType ();
abstract member GetElementType : unit -> Type
Public MustOverride Function GetElementType () As Type

반환

현재 배열, 포인터 또는 참조 형식에서 포함하거나 참조하는 개체의 Type입니다. 현재 null이 배열 또는 포인터가 아니거나, 참조로 전달되지 않거나, 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수나 제네릭 형식을 나타내는 경우에는 Type입니다.The Type of the object encompassed or referred to by the current array, pointer, or reference type, or null if the current Type is not an array or a pointer, or is not passed by reference, or represents a generic type or a type parameter in the definition of a generic type or generic method.

구현

예제

다음 예제는 GetElementType 메서드.The following example demonstrates using the GetElementType method.

using namespace System;
public ref class TestGetElementType{};

int main()
{
   array<Int32>^array = {1,2,3};
   Type^ t = array->GetType();
   Type^ t2 = t->GetElementType();
   Console::WriteLine( "The element type of {0} is {1}.", array, t2 );
   TestGetElementType^ newMe = gcnew TestGetElementType;
   t = newMe->GetType();
   t2 = t->GetElementType();
   Console::WriteLine( "The element type of {0} is {1}.", newMe, t2 == nullptr ? "null" : t2->ToString() );
}

/* This code produces the following output:

The element type of System.Int32[] is System.Int32.
The element type of TestGetElementType is null.
 */
using System;
class TestGetElementType 
{
    public static void Main() 
    {
        int[] array = {1,2,3};
        Type t = array.GetType();
        Type t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.",array, t2.ToString());
        TestGetElementType newMe = new TestGetElementType();
        t = newMe.GetType();
        t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.", newMe, t2==null? "null" : t2.ToString());
    }
}

/* This code produces the following output:

The element type of System.Int32[] is System.Int32.
The element type of TestGetElementType is null.
 */
Imports System

Class TestGetElementType

    Public Shared Sub Main()
        Dim array As Integer() = {1, 2, 3}
        Dim t As Type = array.GetType()
        Dim t2 As Type = t.GetElementType()
        Console.WriteLine("The element type of {0} is {1}.", array, t2.ToString())
        Dim newMe As New TestGetElementType()
        t = newMe.GetType()
        t2 = t.GetElementType()
        If t2 Is Nothing Then
            Console.WriteLine("The element type of {0} is {1}.", newMe, "null")
        Else
            Console.WriteLine("The element type of {0} is {1}.", newMe, t2.ToString())
        End If
    End Sub 'Main
End Class 'TestGetElementType

' This code produces the following output:
'
'The element type of System.Int32[] is System.Int32.
'The element type of TestGetElementType is null.

설명

이 메서드는 반환 null 에 대 한는 Array 클래스입니다.This method returns null for the Array class.

적용 대상

추가 정보