共用方式為


Type.IsEnum 屬性

定義

取得值,指出目前的 Type 是否表示列舉類型。

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

屬性值

Boolean

如果目前 true 代表列舉,則為 Type,否則為 false

實作

範例

下列範例示範如何使用 IsEnum 屬性。

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 型別本身。

如果目前的 Type 代表結構化泛型型別,這個屬性會套用至用來建立型別的泛型型別定義。 例如,如果目前的 Type (代表 MyGenericType<int> MyGenericType(Of Integer) Visual Basic) 中的,則這個屬性的值是由決定 MyGenericType<T>

如果目前 Type 表示泛型型別或泛型方法定義中的類型參數,則這個屬性一律會傳回 false

這是唯讀的屬性。

適用於

另請參閱