How to identity given data type is value type and reference type? [Resolved]

Posted by Allemahesh under C# on 8/19/2013 | Points: 10 | Views : 1882 | Status : [Member] [MVP] | Replies : 2
Can any one tell me if there is any simple way where I can identity whether a given data type is value type or reference type?




Responses

Posted by: Bandi on: 8/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Value Types:
-----------------------
Value type variables directly contain their values, which means that the memory is allocated inline in whatever context the variable is declared. There is no separate heap allocation or garbage collection overhead for value-type variables.
The built-in numeric types are structs, and they have properties and methods that you can access:
// Static method on type Byte.

byte b = Byte.MaxValue;


But you declare and assign values to them as if they were simple non-aggregate types:
byte num = 0xA;

int i = 5;
char c = 'Z';


Reference Types:
-----------------------
A type that is defined as a class, delegate, array, or interface is a reference type. At run time, when you declare a variable of a reference type, the variable contains the value null until you explicitly create an instance of the object by using the new operator, or assign it an object that has been created elsewhere by using new, as shown in the following example:
MyClass mc = new MyClass();

MyClass mc2 = mc;

All arrays are reference types, even if their elements are value types. Arrays implicitly derive from the Array class, but you declare and use them with the simplified syntax that is provided by C#, as shown in the following example:
// Declare and initialize an array of integers. 

int[] nums = { 1, 2, 3, 4, 5 };

// Access an instance property of System.Array.
int len = nums.Length;



Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ssj_Kumar on: 8/20/2013 [Member] Starter | Points: 25

Up
0
Down
Read the below article which will help you on clear understanding the Value type and reference type in detail
http://www.albahari.com/valuevsreftypes.aspx

after reading and understanding the above article you can easily say which is value type and reference type


Regards,
Jayakumar Selvakani

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response