
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Value Type vs Reference Type in C#
Value Type and Reference, both are types in C# −
Value Type
Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. When you declare an int type, the system allocates memory to store the value.
Value Type variables are stored in the stack.
Examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively.
Reference Type
It refers to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value.
Reference Type variables are stored in the heap.
Example of built-in reference types are −
- object
- dynamic
- string
- Related Articles
- SAP ABAP: Using Elementary data type and reference type with keyword VALUE
- Value parameters vs Reference parameters vs Output Parameters in C#
- How to Copy Struct Type Using Value and Pointer Reference in Golang?
- Type difference of character literals in C vs C++
- Pass by reference vs value in Python
- What is a reference/ref parameter of an array type in C#?
- Pass by reference vs Pass by Value in java
- Get the TypeCode for value type Char in C#
- Get the TypeCode for value type Decimal in C#
- Get the TypeCode for value type Int32 in C#
- Get the TypeCode for value type UInt64 in C#
- Get the TypeCode for value type UInt32 in C#
- Get the TypeCode for value type Int16 in C#
- How to convert string type value to array type in JavaScript?
- Passing by pointer Vs Passing by Reference in C++
