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%

Lab 0: Compiler Setup and Check

Lesson 1 of 14 in the free C# Programming Lab notes on Siksha Sarovar, written by Rohit Jangra.

Aim

To install and verify a complete C# tool-chain (.NET SDK with the Roslyn compiler) and execute a first console program, confirming that source code travels the full managed-execution pipeline: C# source → CIL → JIT → native machine code.

Theory

C# is a statically typed, object-oriented language whose compilation model differs fundamentally from C/C++. The Roslyn compiler (csc) does NOT emit native machine code; it emits CIL (Common Intermediate Language) — a stack-based, CPU-neutral instruction set — packaged into a managed assembly (a .dll containing IL, rich metadata and a manifest). At run time the CLR (Common Language Runtime) loads the assembly, verifies the IL for type safety, and RyuJIT (the Just-In-Time compiler) translates each method into native code the first time it executes, caching the result for subsequent calls. This two-stage design buys three things: portability (the same IL runs on Windows, Linux and macOS), safety (array bounds checks, managed references, garbage collection) and runtime optimisation (tiered compilation recompiles hot methods aggressively). Every C# program needs exactly one entry point — a static Main method — which the CLR locates through assembly metadata, not through a linker convention as in C.

Requirements

  • .NET SDK 8.0 (LTS) or later — verify with dotnet --version
  • Any editor: Visual Studio 2022, VS Code + C# Dev Kit, or plain Notepad
  • Alternatively, the built-in RUN CODE compiler on this platform (no installation needed)

Procedure

  1. Install the .NET SDK and confirm the tool-chain: dotnet --version and dotnet --list-sdks.
  2. Scaffold a project: dotnet new console -n Lab0Setup, then cd Lab0Setup.
  3. Replace the generated Program.cs with the code shown here.
  4. Compile and execute in one step: dotnet run. Internally this runs dotnet build (producing bin/Debug/net8.0/Lab0Setup.dll) and then hosts the assembly in the CLR.
  5. Optional: inspect the IL with ildasm (Windows) or the dotnet-ildasm tool and find call void [System.Console]System.Console::WriteLine(string) — visible proof of the two-stage model.

Explanation of the Code

  • using System; imports the System namespace so Console can be used without full qualification (System.Console).
  • class Program — in C# ALL executable code must live inside a type; there are no free functions as in C.
  • static void Main() is the entry point. static means the CLR can invoke it without instantiating Program; void means no exit code is returned (an int return type is also legal and becomes the process exit code).
  • Console.WriteLine(...) is a static method that writes its string plus Environment.NewLine to the standard output stream (stdout). Two calls produce two separate lines.

Expected Output

C# Lab compiler is ready.
Run each practical using the RUN CODE button.

Note

The original experiment list contained a duplicate palindrome practical; it is included only once in this lab to keep the sequence clean.

🎯 Viva Questions

  1. What is CIL/MSIL? — The CPU-neutral intermediate language Roslyn emits; the CLR's JIT converts it to native code at run time.
  2. Difference between the .NET SDK and the .NET Runtime? — The SDK contains compilers and the dotnet CLI for building; the runtime only executes already-built assemblies.
  3. What is an assembly? — A compiled unit (.dll/.exe) containing IL, metadata and a manifest; the unit of deployment and versioning in .NET.
  4. Why must Main be static? — So the CLR can call it directly without constructing an object first.
  5. What does JIT give us over ahead-of-time compilation? — A portable shipped binary plus runtime optimisations (tiered compilation); .NET also offers AOT via dotnet publish when startup time matters.
  6. Which method writes a line to standard output?System.Console.WriteLine, which appends Environment.NewLine automatically.