Type.IsEnum プロパティ

定義

現在の Type が列挙体であるどうかを示す値を取得します。Gets a value indicating whether the current Type represents an enumeration.

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

プロパティ値

現在の true が列挙体を表している場合は Type。それ以外の場合は falsetrue if the current Type represents an enumeration; otherwise, false.

実装

次の例は、プロパティのIsEnum使用方法を示しています。The following example demonstrates how to use the IsEnum property.

using namespace System;
enum class Color
{ Red, Blue, Green };

int main()
{
   Type^ colorType = Color::typeid;
   Type^ enumType = Enum::typeid;
   Console::WriteLine( "Is Color an enum? {0}.", colorType->IsEnum );
   Console::WriteLine( "Is Color a value type? {0}.", colorType->IsValueType );
   Console::WriteLine( "Is Enum an enum Type? {0}.", enumType->IsEnum );
   Console::WriteLine( "Is Enum a value type? {0}.", enumType->IsValueType );
}
// The example displays the following output:
//     Is Color an enum? True.
//     Is Color a value type? True.
//     Is Enum an enum type? False.
//     Is Enum a value type? False.
using System;
public enum Color 
{ Red, Blue, Green }

class TestIsEnum 
{
    public static void Main() 
    {
       Type colorType = typeof(Color);
       Type enumType = typeof(Enum);
       Console.WriteLine("Is Color an enum? {0}.", colorType.IsEnum);
       Console.WriteLine("Is Color a value type? {0}.", colorType.IsValueType);
       Console.WriteLine("Is Enum an enum Type? {0}.", enumType.IsEnum);
       Console.WriteLine("Is Enum a value type? {0}.", enumType.IsValueType);
   }
}
// The example displays the following output:
//     Is Color an enum? True.
//     Is Color a value type? True.
//     Is Enum an enum type? False.
//     Is Enum a value type? False.
Public Enum Color
    Red
    Blue
    Green
End Enum

Class Example
   Public Shared Sub Main()
        Dim colorType As Type = GetType(Color)
        Dim enumType As Type = GetType([Enum])
        Console.WriteLine("Is Color an enum? {0}.", colorType.IsEnum)
        Console.WriteLine("Is Color a value type? {0}.", colorType.IsValueType)
        Console.WriteLine("Is Enum an enum type? {0}.", enumType.IsEnum)
        Console.WriteLine("Is Enum a value type? {0}.", enumType.IsValueType)
    End Sub 
End Class
' The example displays the following output:
'     Is Color an enum? True.
'     Is Color a value type? True.
'     Is Enum an enum type? False.
'     Is Enum a value type? False.

注釈

このプロパティはtrue 、列挙体に対してを返しEnumますが、型自体にはを返しません。This property returns true for an enumeration, but not for the Enum type itself.

現在Typeのが構築ジェネリック型を表している場合、このプロパティは、型が構築された元のジェネリック型定義に適用されます。If the current Type represents a constructed generic type, this property applies to the generic type definition from which the type was constructed. たとえば、現在TypeのがMyGenericType(Of Integer) (Visual Basic MyGenericType<int> ) を表している場合、このプロパティの値はにMyGenericType<T>よって決定されます。For example, if the current Type represents MyGenericType<int> (MyGenericType(Of Integer) in Visual Basic), the value of this property is determined by MyGenericType<T>.

現在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.

このプロパティは読み取り専用です。This property is read-only.

適用対象

こちらもご覧ください