Type.IsSubclassOf(Type) 메서드

정의

현재 Type이 지정된 Type에서 파생되는지 여부를 확인합니다.

public:
 virtual bool IsSubclassOf(Type ^ c);
public virtual bool IsSubclassOf (Type c);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual bool IsSubclassOf (Type c);
abstract member IsSubclassOf : Type -> bool
override this.IsSubclassOf : Type -> bool
[<System.Runtime.InteropServices.ComVisible(true)>]
abstract member IsSubclassOf : Type -> bool
override this.IsSubclassOf : Type -> bool
Public Overridable Function IsSubclassOf (c As Type) As Boolean

매개 변수

c
Type

현재 형식과 비교할 형식입니다.

반환

Boolean

현재 trueType에서 파생되면 c이고, 그렇지 않으면 false입니다. 이 메서드는 false 및 현재 c이 동일한 경우에도 Type를 반환합니다.

구현

특성

예외

c이(가) null인 경우

예제

다음 예제에서는 라는 클래스 Class1 와 라는 파생 클래스를 만듭니다 DerivedC1 . 메서드를 호출 하 여 IsSubclassOf DerivedC1 이의 하위 클래스 임을 보여 줍니다 Class1 .

using System;

public class Class1 { }
public class DerivedC1 : Class1 { }

class IsSubclassTest
{
   public static void Main()
   {
      Console.WriteLine("DerivedC1 subclass of Class1: {0}",
                         typeof(DerivedC1).IsSubclassOf(typeof(Class1)));
   }
}
// The example displays the following output:
//        DerivedC1 subclass of Class1: True
Public Class Class1
End Class

Public Class DerivedC1 : Inherits Class1
End Class

Public Module Example
   Public Sub Main()
      Console.WriteLine("DerivedC1 subclass of Class1: {0}",
                         GetType(DerivedC1).IsSubClassOf(GetType(Class1)))
   End Sub
End Module
' The example displays the following output:
'       DerivedC1 subclass of Class1: True

설명

메서드를 호출 하 여 다음을 확인할 수 있습니다 IsSubclassOf .

  • 한 클래스가 다른 클래스에서 파생 되는지 여부입니다.

  • 형식이에서 파생 되는지 여부를 나타냅니다 ValueType . 그러나는 IsValueType 형식이 값 형식 인지 여부를 확인 하는 보다 효율적인 방법입니다.

  • 형식이에서 파생 되는지 여부를 나타냅니다 Enum . 그러나 메서드는 IsEnum 형식이 열거형 인지 여부를 확인 하는 보다 효율적인 방법입니다.

  • 형식이 대리자 인지, 즉 또는에서 파생 되는지 여부를 나타냅니다 Delegate MulticastDelegate .

IsSubclassOf메서드를 사용 하 여 인터페이스가 다른 인터페이스에서 파생 되는지 여부 또는 클래스가 인터페이스를 구현 하는지 여부를 확인할 수 없습니다. IsAssignableFrom다음 예제와 같이이를 위해 메서드를 사용 합니다.

using System;

public interface IInterface
{
   void Display();
}

public class Implementation : IInterface
{
   public void Display()
   {
      Console.WriteLine("The implementation...");
   }
}

public class Example
{
   public static void Main()
   {
      Console.WriteLine("Implementation is a subclass of IInterface:   {0}",
                        typeof(Implementation).IsSubclassOf(typeof(IInterface)));
      Console.WriteLine("IInterface is assignable from Implementation: {0}",
                        typeof(IInterface).IsAssignableFrom(typeof(Implementation)));
   }
}
// The example displays the following output:
//       Implementation is a subclass of IInterface:   False
//       IInterface is assignable from Implementation: True
Public Interface IInterface
   Sub Display()
End Interface

Public Class Implementation : Implements IInterface
   Public Sub Display() _
      Implements IInterface.Display

      Console.WriteLine("The implementation...")
   End Sub
End Class

Module Example
   Public Sub Main()
      Console.WriteLine("Implementation is a subclass of IInterface:   {0}",
                        GetType(Implementation).IsSubclassOf(GetType(IInterface)))
      Console.WriteLine("IInterface is assignable from Implementation: {0}",
                        GetType(IInterface).IsAssignableFrom(GetType(Implementation)))
   End Sub
End Module
' The example displays the following output:
'       Implementation is a subclass of IInterface:   False
'       IInterface is assignable from Implementation: True

현재이 Type 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우 클래스 제약 조건이 나 System.Object 클래스 제약 조건이 없는 경우에서 파생 됩니다.

참고

인터페이스와 함께 사용 하는 경우를 제외 하 고는 IsSubclassOf 의 반대입니다 IsAssignableFrom . 즉,가 이면 t1.IsSubclassOf(t2) true t2.IsAssignableFrom(t1)true 입니다.

이 메서드는 파생 클래스에 의해 재정의 될 수 있습니다.

적용 대상

추가 정보