Type.IsAbstract Свойство
Определение
public:
property bool IsAbstract { bool get(); };
public bool IsAbstract { get; }
member this.IsAbstract : bool
Public ReadOnly Property IsAbstract As Boolean
Значение свойства
Значение true
, если класс Type является абстрактным; в противном случае — значение false
.true
if the Type is abstract; otherwise, false
.
Реализации
Примеры
В следующем примере создается массив Type объектов, представляющих следующие типы: Contains Type возвращает значение, true
, если указанный объект abstract
. в противном случае возвращается false
.The following example creates an array of Type objects that represent the following types:contains type returns true
if the specified object is abstract
; otherwise, it returns false
.
AbstractClass
, абстрактный класс (класс, помеченный какabstract
C# в иMustInherit
в Visual Basic).AbstractClass
, an abstract class (a class marked asabstract
in C# andMustInherit
in Visual Basic).DerivedClass
, класс, наследующий отAbstractClass
.DerivedClass
, a class that inherits fromAbstractClass
.SingleClass
, не наследуемый класс.SingleClass
, a non-inheritable class. Он определяется какsealed
в C# иNotInheritable
в Visual Basic.It is defined assealed
in C# andNotInheritable
in Visual Basic.ITypeInfo
интерфейс.ITypeInfo
, an interface.ImplementingClass
, класс, реализующий интерфейсITypeInfo
.ImplementingClass
, a class that implements theITypeInfo
interface.
Метод возвращает true
только для AbstractClass
, абстрактного класса и ITypeInfo
интерфейса.The method returns true
only for AbstractClass
, the abstract class, and ITypeInfo
, the interface.
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
в следующих случаях:The IsAbstract property returns true
in the following cases:
Текущий тип является абстрактным; то есть он не может быть создан, но может служить только базовым классом для производных классов.The current type is abstract; that is, it cannot be instantiated, but can only serve as the base class for derived classes. В C#абстрактные классы помечаются ключевым словом abstract . в Visual Basic они помечаются ключевым словом MustInherit .In C#, abstract classes are marked with the abstract keyword; in Visual Basic, they are marked with the MustInherit keyword.
Текущий тип является интерфейсом.The current type is an interface.
Если текущий Type представляет параметр типа в определении универсального типа или универсального метода, это свойство всегда возвращает false
.If the current Type represents a type parameter in the definition of a generic type or generic method, this property always returns false
.