Type.IsClass プロパティ

定義

Type がクラスまたはデリゲートである (つまり値型やインターフェイスではない) かどうかを示す値を取得します。

public:
 property bool IsClass { bool get(); };
public bool IsClass { get; }
member this.IsClass : bool
Public ReadOnly Property IsClass As Boolean

プロパティ値

true がクラスである場合は Type。それ以外の場合は false

実装

次の例では、型のインスタンスを作成し、その型がクラスであるかどうかを示します。

using namespace System;
using namespace System::Reflection;
public ref class MyDemoClass{};

int main()
{
   try
   {
      Type^ myType = Type::GetType( "MyDemoClass" );
      
      // Get and display the 'IsClass' property of the 'MyDemoClass' instance.
      Console::WriteLine( "\nIs the specified type a class? {0}.", myType->IsClass );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "\nAn exception occurred: {0}.", e->Message );
   }

}
using System;
using System.Reflection;

public  class MyDemoClass
{
}

public class MyTypeClass
{
    public static void Main(string[] args)
    {
        try
        {
            Type  myType = typeof(MyDemoClass);
            // Get and display the 'IsClass' property of the 'MyDemoClass' instance.
            Console.WriteLine("\nIs the specified type a class? {0}.", myType.IsClass);
        }
        catch(Exception e)
        {
            Console.WriteLine("\nAn exception occurred: {0}." ,e.Message);
        }
    }
}
type MyDemoClass = class end

try
    let myType = typeof<MyDemoClass>
    // Get and display the 'IsClass' property of the 'MyDemoClass' instance.
    printfn $"\nIs the specified type a class? {myType.IsClass}."
with e ->
    printfn $"\nAn exception occurred: {e.Message}."
Imports System.Reflection

Public Class MyDemoClass
End Class

Public Class MyTypeClass
    Public Shared Sub Main()
        Try
            Dim myType As Type = GetType(MyDemoClass)
            ' Get and display the 'IsClass' property of the 'MyDemoClass' instance.
            Console.WriteLine(ControlChars.Cr + "Is the specified type a class? {0}.", myType.IsClass.ToString())
        Catch e As Exception
            Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}.", e.Message.ToString())
        End Try
    End Sub
End Class

注釈

このプロパティは、 true デリゲートと同様にクラスに対して を返します。 ボックス化されている場合でも、値型 (構造体と列挙型の場合) に対して が返 false されます。

現在 Type の がジェネリック型またはジェネリック メソッドの定義で型パラメーターを表す場合、このプロパティは常に を返します true。 現在 Type の が構築されたジェネリック型を表す場合、ジェネリック型定義がクラス定義である場合、つまり true インターフェイスや値型は定義されません。

注意

このプロパティは、 true クラスと ValueType クラスを表すインスタンスに対Typeして をEnum返します。 これら 2 つのクラスはそれぞれ列挙型と値型の基本型ですが、列挙型や値型自体ではありません。 詳細については、IsValueType プロパティおよび IsEnum プロパティを参照してください。

列挙値は TypeAttributes.ClassSemanticsMask 、型宣言をクラスまたはインターフェイスとして区別します。 ただし、クラスと値の型の両方が 属性で TypeAttributes.Class マークされます。 型の Attributes プロパティの値を取得し、その値を TypeAttributes.ClassSemanticsMask 使用して、型が値型ではなくクラスであるかどうかを判断する場合は、 プロパティも呼び出す IsValueType 必要があります。 列挙型の TypeAttributes 例には、追加の情報とサンプルが含まれています。

このプロパティは読み取り専用です。

適用対象

こちらもご覧ください