Article Groups

# Reference types and value types

In the last tutorial you learnt that majority of the types in C# are divided into two groups – classes and structures. There are two more words which are related to this concept – reference types and value types. When you create a variable in C# it will either be called a reference type variable or a value type variable.

## A simple trick

A very simple trick to tell whether a variable is of reference type or a value type is to check if it is a variable of the type class or structure. If suppose you have a class Test and you write

Test t;

Then t will be considered a reference type variable. Similarly if you have a structure Test and you write

Test t;

Then t will be considered a value type variable.

## What is the difference between reference types and value types

Anything which we call a reference type is a pointer and holds an address. Anything which we call a value type is not a pointer and holds the actual value.

Also another important point to remember is that when you create an object from a class it gets memory on the heap and when you create an object from a structure it gets memory on the stack. For now even if you don’t actually understand these concepts don’t worry. Soon we will be using and discussing these concepts in details and you should get a better understanding. For now just remember the information discussed about classes and structure and also about reference types and value types.

### E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization