Type.IsValueType Type.IsValueType Type.IsValueType Type.IsValueType Property

定義

取得值,指出 Type 是否為實值類型。Gets a value indicating whether the Type is a value type.

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

屬性值

如果 true 是實值類型,則為 Type,否則為 falsetrue if the Type is a value type; otherwise, false.

實作

範例

下列範例會建立類型MyEnum的變數、檢查IsValueType屬性,並顯示結果。The following example creates a variable of type MyEnum, checks for the IsValueType property, and displays the result.

using namespace System;

// Declare an enum type.
public enum class NumEnum
{
   One, Two
};

int main()
{
    bool flag = false;
    NumEnum testEnum = NumEnum::One;
      
    // Get the type of myTestEnum.
    Type^ t = testEnum.GetType();
      
    // Get the IsValueType property of the myTestEnum
    // variable.
    flag = t->IsValueType;
    Console::WriteLine("{0} is a value type: {1}", t->FullName, flag);
}
using System;

// Declare an enum type.
enum NumEnum { One, Two }

public class Example
{

    public static void Main(string []args)
    {
        bool flag = false;
        NumEnum testEnum = NumEnum.One;
        // Get the type of myTestEnum.
        Type t = testEnum.GetType();
        // Get the IsValueType property of the myTestEnum variable.
        flag = t.IsValueType;
        Console.WriteLine("{0} is a value type: {1}", t.FullName, flag);
    }
}
// The example displays the following output:
//        NumEnum is a value type: True
' Declare an enum type.
Enum NumEnum
    One
    Two
End Enum
    
Public Class Example

    Public Shared Sub Main()
        Dim flag As Boolean = False
        Dim testEnum As NumEnum = NumEnum.One
        ' Get the type of myTestEnum.
        Dim t As Type = testEnum.GetType()
        ' Get the IsValueType property of the myTestEnum variable.
         flag = t.IsValueType()
         Console.WriteLine("{0} is a value type: {1}", t.FullName, flag)
     End Sub 
 End Class  
' The example displays the following output:
'       NumEnum is a value type: True

備註

實數值型別是以位序清單示的類型;實數值型別不是類別或介面。Value types are types that are represented as sequences of bits; value types are not classes or interfaces. 在某些程式設計語言中,實數值型別稱為「結構」。Value types are referred to as "structs" in some programming languages. Enum 是實數值型別的特殊案例。Enums are a special case of value types.

這個屬性falseValueType針對類別傳回,因為ValueType不是實值型別本身。This property returns false for the ValueType class, because ValueType is not a value type itself. 它是所有實數值型別的基類,因此可以指派任何實數值型別。It is the base class for all value types, and therefore any value type can be assigned to it. 如果ValueType本身是實值型別,就無法這麼做。This would not be possible if ValueType itself was a value type. 當實數值型別指派給類型ValueType的欄位時,會進行裝箱。Value types are boxed when they are assigned to a field of type ValueType.

這個屬性true會傳回列舉的,但不會Enum傳回類型本身。This property returns true for enumerations, but not for the Enum type itself. 如需示範此行為的範例,請IsEnum參閱。For an example that demonstrates this behavior, see IsEnum.

這個屬性是唯讀的。This property is read-only.

適用於

另請參閱