Type.IsAbstract 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
Type이 추상이며 재정의되어야 하는지 여부를 나타내는 값을 가져옵니다.
public:
property bool IsAbstract { bool get(); };
public bool IsAbstract { get; }
member this.IsAbstract : bool
Public ReadOnly Property IsAbstract As Boolean
속성 값
Type이 추상이면 true이고, 그렇지 않으면 false입니다.
구현
예제
다음 예제에서는 다음 Type 형식을 나타내는 개체의 배열을 만듭니다. 지정된 개체가 이면 contains 형식이 를 true abstract 반환하고, 그렇지 않으면 를 false 반환합니다.
AbstractClass- 추상abstract클래스(C#에서는 로 표시되고 Visual Basic 표시된MustInherit클래스)입니다.DerivedClass- 에서 상속되는AbstractClass클래스입니다.SingleClass상속할 수 없는 클래스입니다. C# 및 Visual Basic 로sealed정의됩니다.NotInheritableITypeInfo- 인터페이스입니다.ImplementingClass- 인터페이스를 구현하는ITypeInfo클래스입니다.
메서드는 true 에 대해서만 AbstractClass 반환 , 추상 클래스 및 ITypeInfo , 인터페이스입니다.
using System;
public abstract class AbstractClass
{}
public class DerivedClass : AbstractClass
{}
public sealed class SingleClass
{}
public interface ITypeInfo
{
string GetName();
}
public class ImplementingClass : ITypeInfo
{
public string GetName()
{
return this.GetType().FullName;
}
}
delegate string InputOutput(string inp);
public class Example
{
public static void Main()
{
Type[] types= { typeof(AbstractClass),
typeof(DerivedClass),
typeof(ITypeInfo),
typeof(SingleClass),
typeof(ImplementingClass),
typeof(InputOutput) };
foreach (var type in types)
Console.WriteLine("{0} is abstract: {1}",
type.Name, type.IsAbstract);
}
}
// The example displays the following output:
// AbstractClass is abstract: True
// DerivedClass is abstract: False
// ITypeInfo is abstract: True
// SingleClass is abstract: False
// ImplementingClass is abstract: False
// InputOutput is abstract: False
Public MustInherit Class AbstractClass
End Class
Public Class DerivedClass : Inherits AbstractClass
End Class
Public NotInheritable Class SingleClass
End Class
Public Interface ITypeInfo
Function GetName() As String
End Interface
Public Class ImplementingClass : Implements ITypeInfo
Public Function GetName() As String _
Implements ITypeInfo.GetName
Return Me.GetType().FullName
End Function
End Class
Delegate Function InputOutput(inp As String) As String
Module Example
Public Sub Main()
Dim types() As Type = { GetType(AbstractClass),
GetType(DerivedClass),
GetType(ITypeInfo),
GetType(SingleClass),
GetType(ImplementingClass),
GetType(InputOutput) }
For Each type In types
Console.WriteLine("{0} is abstract: {1}",
type.Name, type.IsAbstract)
Next
End Sub
End Module
' The example displays the following output:
' AbstractClass is abstract: True
' DerivedClass is abstract: False
' ITypeInfo is abstract: True
' SingleClass is abstract: False
' ImplementingClass is abstract: False
' InputOutput is abstract: False
설명
IsAbstract속성은 다음과 같은 경우에 를 true 반환합니다.
현재 형식은 추상 형식입니다. 즉, 인스턴스화할 수 없지만 파생 클래스의 기본 클래스로만 사용할 수 있습니다. C#에서 추상 클래스는 abstract 키워드로 표시됩니다. Visual Basic MustInherit 키워드로 표시됩니다.
현재 형식이 인터페이스입니다.
현재 가 Type 제네릭 형식 또는 제네릭 메서드 정의에서 형식 매개 변수를 나타내는 경우 이 속성은 항상 false 를 반환합니다.