Export (0) Print
Expand All

Type.IsValueType Property

Gets a value indicating whether the Type is a value type.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public:
virtual property bool IsValueType {
	bool get () sealed;
}
/** @property */
public final boolean get_IsValueType ()

public final function get IsValueType () : boolean

Not applicable.

Property Value

true if the Type is a value type; otherwise, false.

Value types are those that are represented as sequences of bits; value types are not classes or interfaces. These are referred to as "structs" in some programming languages. Enums are a special case of value types.

This property returns false for the ValueType class.

This property returns true for enumerations, but not for the Enum type itself. For an example that demonstrates this behavior, see IsEnum.

This property is read-only.

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.
enum class MyEnum
{
   One, Two
};

int main()
{
   try
   {
      bool myBool = false;
      MyEnum myTestEnum = MyEnum::One;
      
      // Get the type of myTestEnum.
      Type^ myType = myTestEnum.GetType();
      
      // Get the IsValueType property of the myTestEnum
      // variable.
      myBool = myType->IsValueType;
      Console::WriteLine( "\nIs {0} a value type? {1}.", myType->FullName, myBool );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "\nAn exception occurred: {0}", e->Message );
   }

}


package SystemType;
   
import System.*;

public class MyClass
{
    // Declare an enum type.
    static class MyEnum
    {
        private int member;

        MyEnum()
        {
            member = 0;
        } //MyEnum

        MyEnum(int n)
        {
            member = n;
        } //MyEnum

        public static final int one = 0;
        public static final int two = 1;
    } //MyEnum

    public static void main(String[] args)
    {
        try {
            boolean myBool = false;
            MyEnum myTestEnum = new MyEnum(MyEnum.one);

            // Get the type of myTestEnum.
            Type myType = myTestEnum.GetType();

            // Get the IsValueType property of the myTestEnum variable.
            myBool = myType.get_IsValueType();
            Console.WriteLine("\nIs {0} a value type? {1}.",
                myType.get_FullName(), ((System.Boolean)myBool).ToString());
        }
        catch (System.Exception e) {
            Console.WriteLine("\nAn exception occurred: {0}", e.get_Message());
        }
    } //main
} //MyClass

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft