Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.IsValueType Property

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

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

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

public final function get IsValueType () : boolean

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 System;
namespace SystemType
{
    public class MyClass
    {
        // Declare an enum type.
        enum MyEnum
        {
            One,
            Two
        }
        public static void Main(string []args)
        {
            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.ToString());
            }
            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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show:
© 2014 Microsoft