C# Tutorial Beginners - Part 1

Welcome back to another story of C# Tutorial for Beginners. This article is all about Stack and Heap data, Garbage collector, Primitive datatypes and Boxing and Unboxing . Your reading this article because you know about programming and you would like to learn more about it. I appreciate it and let’s get started.

  1. Stack Allocation
  2. Heap Allocation

Stack Allocation :

Heap Allocation :

Example of stack and heap memory allocation

What is Garbage Collection and Why We Need It?

  1. Value Type
  2. Reference Type

Definition:

Performance implication of Boxing and Unboxing :

Boxing :

  • The process of Converting a Value type(char, int etc.) to a Reference type(object) is called Boxing.
  • The Value type is always stored in Stack. The Referenced Type is stored in Heap.

Unboxing :

  • The process of converting reference type into the value type is known as Unboxing.
  • Description : Declaration a value type variable (num), which is integer type and assigned with integer value 23. Now, create a reference object type (obj).The explicit operation for boxing create an value type integer i . Then the referenced type residing on Heap is copy to stack as shown in below figure :

I hope this guide has been helpful for you 😃!!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store