← .NET / C# Developer
Day 1 · C# Basics: .NET, Types, Value vs Reference, Strings, Control Flow, Arrays and Nullable
.NET / C# Developer · Crash Course
Day 1

C# Basics: .NET, Types, Value vs Reference, Strings, Control Flow, Arrays and Nullable

⏱ About 90 minutes · 23 pages
By the end of today you will be able to
  • ✔ Explain CLR, IL, JIT, CTS and the .NET runtime clearly in an interview
  • ✔ Pick the right C# type and predict conversions, overflow and operator results
  • ✔ Explain value types versus reference types, boxing and string equality with examples
  • ✔ Trace if, switch, loops, arrays and nullable values by hand without mistakes
  1. What .NET is, and where C# fits
  2. From C# source to running code: IL and JIT
  3. Your first C# program

What .NET is, and where C# fits

The first .NET interview question is almost always "What is the CLR?" or "What is the difference between .NET Framework and .NET?", so learn this page well.

C# (said "C sharp") is a modern, object-oriented, type-safe language made by Microsoft. .NET is the platform that runs C# programs. C# is the language; .NET is the runtime, libraries and tools.

.NET has three main parts:

Part Full form What it does
CLR Common Language Runtime Runs your code: loads it, JIT-compiles it, manages memory with the garbage collector, handles exceptions and security checks
BCL Base Class Library Ready-made classes: Console, String, Math, List<T>, file and network classes
SDK Software Development Kit Tools to build programs: the C# compiler and the dotnet command-line tool

.NET Framework versus .NET (Core)

The original .NET Framework runs only on Windows. Microsoft later built .NET Core, which is open source and cross-platform (Windows, Linux, macOS). From version 5 onward the name became simply .NET. New projects use modern .NET; older company projects may still use .NET Framework.

Your C# program (source code) Base Class Library (BCL) Console · String · Math · Collections · IO CLR (Common Language Runtime) JIT compiler · Garbage collector · Type safety
✍️ Example 1 — Language or platform?
  1. Question: "Is LINQ part of C# or part of .NET?"

  2. The query keywords (from, where, select) are C# language features.

  3. The methods that do the work (Where, Select) live in a .NET library.

  4. Answer: both — the syntax is C#, the implementation is in the .NET libraries.

.NET / C# Developer · Day 12 / 5

From C# source to running code: IL and JIT

"What is IL?" and "What is JIT?" are standard fresher questions, and they also explain why .NET programs can run on many machines.

C# is not compiled straight to machine code. It goes through two steps.

  1. Compile. The C# compiler (Roslyn) turns your code into IL — Intermediate Language, also called CIL or MSIL — stored in an assembly (.dll or .exe) together with metadata describing every type and method.
  2. Run. The CLR loads the assembly, and the JIT (Just-In-Time) compiler turns each method's IL into native code the first time it is called. Later calls reuse that native code.
flowchart LR
  A[Program.cs<br/>C# source] -->|C# compiler| B[Assembly .dll<br/>IL + metadata]
  B -->|dotnet run| C[CLR loads assembly]
  C --> D[JIT compiles method<br/>on first call]
  D --> E[Native machine code]
  E --> F[Output]

CTS, CLS and managed code

  • CTS (Common Type System) defines the types every .NET language shares. C#'s int and VB.NET's Integer both map to the same CTS type, System.Int32.
  • CLS (Common Language Specification) is a smaller rule set; a CLS-compliant library works from any .NET language.
  • Managed code runs under the CLR; unmanaged code (such as a native C++ DLL) runs outside it.
  • The garbage collector (GC) frees heap objects that nothing points to any more, so you do not call free or delete yourself.
✍️ Example 2 — Where is the error caught?
  1. Code: int fare = "250";

  2. The compiler sees a string being put into an int.

  3. Answer: compile time — no assembly is produced.

✍️ Example 3 — Why the first call is slower
  1. A method runs for the first time, so the JIT must compile its IL.

  2. The second call reuses the native code already made.

  3. Answer: the first call pays a small JIT cost; later calls do not.

🙋 Try it now

What does the C# compiler produce from your .cs files?

.NET / C# Developer · Day 13 / 5

Your first C# program

Interviewers ask you to write tiny programs on paper, so you must know the exact shape of a C# file.

Here is the classic form of a console program:

using System;

namespace HelloApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Namaste, ");
            Console.WriteLine("Priya");
            Console.WriteLine(args.Length);
        }
    }
}

Run with no command-line arguments, it prints:

Namaste, Priya
0
  • using System; lets you write Console instead of System.Console; namespace groups related classes.
  • Main is the entry point. It must be static. Valid forms include static void Main(), static int Main(string[] args) and static async Task Main().
  • Console.Write prints without a new line; Console.WriteLine adds a new line at the end.
  • args holds command-line arguments; with none, its length is 0, not null.

Top-level statements

Since C# 9 you can skip the class and Main completely. The compiler creates them for you:

Console.WriteLine("Train 12951 leaves at 17:00");

New console projects also turn on implicit usings, so common namespaces such as System are already imported.

The dotnet command line

Command What it does
dotnet new console -n Billing Creates a new console project named Billing
dotnet build Compiles the project to an assembly
dotnet run Builds (if needed) and runs it
✍️ Example 4 — Spot the output
  1. Console.Write("A"); Console.Write("B"); Console.WriteLine("C"); Console.Write("D");

  2. Write keeps the cursor on the same line, WriteLine ends the line after C.

  3. Answer: "ABC" on the first line and "D" on the second.

✍️ Example 5 — Will it compile?
  1. class Program { void Main() { } } — Main is not static.

  2. The compiler cannot find a valid static entry point.

  3. Answer: it builds as a library but fails as a console app — "no suitable static Main".

.NET / C# Developer · Day 14 / 5
Free preview ends here

Keep going with the full course

Day 1 has 23 pages. You have read the first 3.

See what's inside →