Object.GetType 메서드
현재 인스턴스의 Type을 가져옵니다.
네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public Function GetType As Type
‘사용 방법
Dim instance As Object
Dim returnValue As Type
returnValue = instance.GetType
public Type GetType ()
public:
Type^ GetType ()
public Type GetType ()
public function GetType () : Type
반환 값
현재 인스턴스의 런타임 형식을 나타내는 Type 인스턴스입니다.
설명
동일한 런타임 형식을 갖는 두 개체 x와 y에 대해 Object.ReferenceEquals(x.GetType(),y.GetType())
은 true를 반환합니다.
Type 개체는 현재 Object의 클래스와 연관된 메타데이터를 노출합니다.
예제
다음 코드 예제에서는 GetType이 현재 인스턴스의 런타임 형식을 반환한다는 것을 보여 줍니다.
using System;
public class MyBaseClass: Object {
}
public class MyDerivedClass: MyBaseClass {
}
public class Test {
public static void Main() {
MyBaseClass myBase = new MyBaseClass();
MyDerivedClass myDerived = new MyDerivedClass();
object o = myDerived;
MyBaseClass b = myDerived;
Console.WriteLine("mybase: Type is {0}", myBase.GetType());
Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());
Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());
Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType());
}
}
/*
This code produces the following output.
mybase: Type is MyBaseClass
myDerived: Type is MyDerivedClass
object o = myDerived: Type is MyDerivedClass
MyBaseClass b = myDerived: Type is MyDerivedClass
*/
using namespace System;
public ref class MyBaseClass: public Object{};
public ref class MyDerivedClass: public MyBaseClass{};
int main()
{
MyBaseClass^ myBase = gcnew MyBaseClass;
MyDerivedClass^ myDerived = gcnew MyDerivedClass;
Object^ o = myDerived;
MyBaseClass^ b = myDerived;
Console::WriteLine( "mybase: Type is {0}", myBase->GetType() );
Console::WriteLine( "myDerived: Type is {0}", myDerived->GetType() );
Console::WriteLine( "object o = myDerived: Type is {0}", o->GetType() );
Console::WriteLine( "MyBaseClass b = myDerived: Type is {0}", b->GetType() );
}
/*
This code produces the following output.
mybase: Type is MyBaseClass
myDerived: Type is MyDerivedClass
object o = myDerived: Type is MyDerivedClass
MyBaseClass b = myDerived: Type is MyDerivedClass
*/
import System.*;
public class MyBaseClass extends Object
{
} //MyBaseClass
public class MyDerivedClass extends MyBaseClass
{
} //MyDerivedClass
public class Test
{
public static void main(String[] args)
{
MyBaseClass myBase = new MyBaseClass();
MyDerivedClass myDerived = new MyDerivedClass();
Object o = myDerived;
MyBaseClass b = myDerived;
Console.WriteLine("mybase: Type is {0}", myBase.GetType());
Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());
Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());
Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType());
} //main
} //Test
/*
This code produces the following output.
mybase: Type is MyBaseClass
myDerived: Type is MyDerivedClass
object o = myDerived: Type is MyDerivedClass
MyBaseClass b = myDerived: Type is MyDerivedClass
*/
import System
public class MyBaseClass extends Object {
}
public class MyDerivedClass extends MyBaseClass {
}
public class Test {
public static function Main() {
var myBase : MyBaseClass = new MyBaseClass();
var myDerived : MyDerivedClass = new MyDerivedClass();
var o = myDerived;
var b : MyBaseClass = myDerived;
Console.WriteLine("mybase: Type is {0}", myBase.GetType());
Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());
Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());
Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType());
}
}
Test.Main();
/*
This code produces the following output.
mybase: Type is MyBaseClass
myDerived: Type is MyDerivedClass
object o = myDerived: Type is MyDerivedClass
MyBaseClass b = myDerived: Type is MyDerivedClass
*/
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원