Check if a Type is a value type in CSharp

Description

The following code shows how to check if a Type is a value type.

Example


/*from w w  w .  j  ava  2 s.  c o  m*/
using System;
namespace SystemType
{
    public class MyClass
    {
        enum MyEnum
        {
            One,
            Two
        }
        public static void Main(string []args)
        {
            bool myBool = false;
            MyEnum myTestEnum = MyEnum.One;
            Type myType = myTestEnum.GetType();
            myBool = myType.IsValueType;
            Console.WriteLine("\nIs {0} a value type? {1}.", myType.FullName, myBool.ToString());
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type