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의 필드에 할당될 때 boxed됩니다.

이 속성은 열거형에 대해 를 반환하지만 형식 자체에는 반환 trueEnum 되지 않습니다. 이 동작을 보여 주는 예제는 를 참조하세요 IsEnum.

이 속성은 읽기 전용입니다.

적용 대상

추가 정보