How to distinguish a type of type ValueType or RefereceType?

some simple types like int, string, .... it's easy to see that they are ValueTypes or RefrenceTypes. But I want to know if there is a way to distinguish?

+5
source share
2 answers

All structures, enumerations, and native types are value types.

At runtime, you can check the following:

Type type = typeof(TypeName);

if (type.IsValueType) 
{ 
   //...
}
+7
source

Strings are not value types.

Here is a list of the most commonly used value types :

  • bool (System.Boolean)
  • byte (System.Byte)
  • char (System.Char)
  • decimal (System.Decimal)
  • double (System.Double)
  • float (System.Single)
  • int (System.Int32)
  • long (System.Int64)
  • sbyte (System.SByte)
  • short (System.Int16)
  • uint (System.UInt32)
  • ulong (System.UInt64)
  • ushort (System.UInt16)
  • System.DateTime

:

  • ,
  • ,

.

+4

All Articles