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.

[Visual Basic]
Public ReadOnly Property IsValueType As Boolean
[C#]
public bool IsValueType {get;}
[C++]
public: __property bool get_IsValueType();
[JScript]
public function get IsValueType() : Boolean;

Property Value

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

Remarks

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 true for enumerations, but not for the Enum type itself, which is a class. For an example that demonstrates this behavior, see IsEnum.

This property is read-only.

Example

[Visual Basic, C#, C++] The following example creates a variable of type MyEnum, checks for the IsValueType property, and displays the result.

[Visual Basic] 
Imports System
Imports Microsoft.VisualBasic
Namespace SystemType
    Public Class [MyClass]

        ' Declare an enum type.
        Enum MyEnum
            One
            Two
        End Enum 'MyEnum

        Public Overloads Shared Sub Main()
            Try
                Dim myBool As Boolean = False
                Dim myTestEnum As MyEnum = MyEnum.One
                ' Get the type of myTestEnum.
                Dim myType As Type = myTestEnum.GetType()
                ' Get the IsValueType property of the myTestEnum variable.
                myBool = myType.IsValueType
                Console.WriteLine(ControlChars.Cr + "Is {0} a value type? {1}.", myType.FullName, myBool.ToString())
            Catch e As Exception
                Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}", e.Message.ToString())
            End Try
        End Sub 'Main
    End Class '[MyClass] 
End Namespace 'SystemType

[C#] 
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);
            }
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;

// Declare an enum type.
__value enum MyEnum {
   One,
   Two
};

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Type Class | Type Members | System Namespace | TypeAttributes | IsClass | IsInterface | ValueType | IsValueTypeImpl | TypeAttributes | IsClass | IsInterface | ValueType | IsValueTypeImpl

Show:
© 2014 Microsoft