Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Variables and Data Types

Lesson 12 of 27 in the free C# Programming notes on Siksha Sarovar, written by Rohit Jangra.

Detailed Data Type Reference

C# is a strongly typed language, meaning every variable has a specific type, and you cannot assign incompatible values.

Study Deep: Stack vs. Heap Memory

Understanding where your data lives is crucial for performance tuning:

  1. The Stack: Stores Value Types (int, double, bool). It is small, extremely fast, and automatically managed via a "Last-In, First-Out" (LIFO) structure. Memory is freed as soon as the variable goes out of scope.
  2. The Heap: Stores Reference Types (Objects, Strings, Arrays). It is much larger but slower. Objects on the heap are managed by the Garbage Collector.
  • Key Difference: When you copy a value type, you get a new copy of the data. When you copy a reference type, you get a new "pointer" to the same data on the heap.

1. Value Types (Primitive)

These store the actual data. Use less memory and are faster.

C# Type.NET TypeSizeRange / Description
byteSystem.Byte1 byte0 to 255
intSystem.Int324 bytes-2B to +2B
longSystem.Int648 bytesVery large integers
floatSystem.Single4 bytesPrecision: ~7 digits
doubleSystem.Double8 bytesPrecision: ~15 digits
decimalSystem.Decimal16 bytesPrecision: ~28 digits
boolSystem.Boolean1 bytetrue / false
charSystem.Char2 bytesUnicode character