tabs

Thursday, October 31, 2013

Value Types and Reference Types in .Net

What is a Data Type?

Data Types in the programming scenario are the categorized sections,which are based on the type of data stored in them.Generally different types of data are stored in different memory with different structures such as stack or heap memories.
Some data types holds its data within its own memory allocation and some store only the address of the data[Data is present at some other location].So Data Types are categorized based on the way how they store their values .

Categories of Data Types
Generally we come across many data types in our programming journey like int, char, float,object etc. But to be clear all the Data Types are classified into two sections , they are:
  1. Value Type
  2. Reference Type
Let us discuss them in detail:

Value Type:
  • The Data Types which store their values directly in their stack memory are known as Value Types.
  • Among the built-in Data Types ,except 'String' and 'Object' all other data types are considered value types
  • Among user defined data types 'structure' and 'enum' are taken as value types.
  • Examples: All numeric data types, char bool, date, structures and enum etc.

Reference Type
  • Reference Types are those which store their values in heap memory and the address of those values are stored in stack memory as variables.
  • Among the built-in data types 'string' and 'object' are taken as Reference Types.
  • Among user defined data types Arrays, Class, Interface, and Delegate etc are taken as reference types.
  • Examples:string, object, arrays, delegates, interface etc.

Hope it helps you, Please feel free to suggest and post your valuable comments.

No comments:

Post a Comment