C# Type IsValueType

Description

Type IsValueType gets a value indicating whether the Type is a value type.

Syntax

Type.IsValueType has the following syntax.


public bool IsValueType { get; }

Example

The following example creates a variable of type MyEnum, checks for the IsValueType property, and displays the result.


/*from w  w w.  jav a 2s .c o m*/
using System;
namespace SystemType
{
    public class MyClass
    {
        enum MyEnum
        {
            One,
            Two
        }
        public static void Main(string []args)
        {
            try
            {
                bool myBool = false;
                MyEnum myTestEnum = MyEnum.One;
                Type myType = myTestEnum.GetType();
                Console.WriteLine(myType.IsValueType);
            }
            catch (Exception e)
            {
                Console.WriteLine("\nAn exception occurred: {0}", e.Message);
            }
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version