Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to distinguish that a type is ValueType Or RefereceType?

some simple types like int, string , ....are easy to realize that they are ValueTypes Or RefrenceTypes. But I wanna to know is there any way to distinguish?

like image 595
odiseh Avatar asked Jul 23 '09 06:07

odiseh


1 Answers

All structs, enums and native types are value types.

At runtime you can check like this:

Type type = typeof(TypeName);

if (type.IsValueType) 
{ 
   //...
}
like image 139
Philippe Leybaert Avatar answered Nov 09 '22 14:11

Philippe Leybaert