Type.IsValueType プロパティ
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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。
このプロパティは読み取り専用です。
製品 | バージョン |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。