How to

find out whether type is value or reference type

Published: 20. October 2011 | Updated: 26. October 2011
License: Microsoft Public License (MS-PL)
Categories: Framework » Types
Tags: Basics C#
Was this snippet helpful for you? YESYES / NONO
int number = 123456;
Type type = number.GetType();
Console.WriteLine(type.IsValueType ? "Value type" : "Reference type");

string text = "test";
type = text.GetType();
Console.WriteLine(type.IsValueType ? "Value type" : "Reference type");
Console Output:
Value type
Reference type
Send us feedback about this snippet »



Related Snippets: