Type.IsValueType Właściwość

Definicja

Pobiera wartość wskazującą, czy Type jest typem wartości.

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

Wartość właściwości

true jeśli jest Type typem wartości; w przeciwnym razie false.

Implementuje

Przykłady

Poniższy przykład tworzy zmienną typu MyEnum, sprawdza IsValueType właściwość i wyświetla wynik.

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 testEnum.
    Type^ t = testEnum.GetType();
      
    // Get the IsValueType property of the testEnum
    // 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 testEnum.
        Type t = testEnum.GetType();
        // Get the IsValueType property of the testEnum 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.
type NumEnum = One = 1 | Two = 2

let testEnum = NumEnum.One
// Get the type of testEnum.
let t = testEnum.GetType()
// Get the IsValueType property of the testEnum variable.
let flag = t.IsValueType
printfn $"{t.FullName} is a value type: {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

Uwagi

Typy wartości to typy reprezentowane jako sekwencje bitów; typy wartości nie są klasami ani interfejsami. Typy wartości są określane jako "struktury" w niektórych językach programowania. Wyliczenia to specjalny przypadek typów wartości.

Ta właściwość zwraca false wartość dla ValueType klasy, ponieważ ValueType nie jest typem wartości. jest to klasa bazowa dla wszystkich typów wartości, a zatem do niej można przypisać dowolny typ wartości. Nie byłoby to możliwe, jeśli ValueType sam był typem wartości. Typy wartości są wyświetlane po przypisaniu ich do pola typu ValueType.

Ta właściwość zwraca true wartość dla wyliczenia, ale nie dla Enum samego typu. Aby zapoznać się z przykładem tego zachowania, zobacz IsEnum.

Ta właściwość jest tylko do odczytu.

Dotyczy

Zobacz też