Type.IsValueType プロパティ

定義

Type が値型かどうかを示す値を取得します。

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

プロパティ値

true が値型である場合は Type。それ以外の場合は false

実装

次の例では、 型 MyEnumの変数を作成し、 プロパティを IsValueType チェックし、結果を表示します。

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

注釈

値型は、ビットのシーケンスとして表される型です。値型はクラスまたはインターフェイスではありません。 値型は、一部のプログラミング言語では "構造体" と呼ばれます。 列挙型は、値型の特殊なケースです。

は値型自体ではないのでValueType、このプロパティは クラスに対ValueTypeして を返falseします。 これはすべての値型の基本クラスであるため、任意の値型を割り当てることができます。 それ自体が値型の場合 ValueType 、これは不可能です。 値型は、 型 ValueTypeのフィールドに割り当てられるときにボックス化されます。

このプロパティは列挙型を true 返しますが、型自体には Enum 返しません。 この動作を示す例については、「」を参照してください IsEnum

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

適用対象

こちらもご覧ください