C# Interview Preparation Guide (10-Day Crash Course)
Day 1: Introduction to C# and .NET
What is C#?
• A modern, object-oriented programming language developed by Microsoft.
• Runs on the .NET platform.
Theory: C# (pronounced C-Sharp) is used to develop all kinds of applications such as desktop apps, web
apps, mobile apps, and games. It is similar in syntax to Java and C++, making it easier to learn if you have
some programming background.
.NET Platform Overview
• .NET is a framework that supports multiple languages (C#, VB.NET, F#).
• Key components: CLR (Common Language Runtime), BCL (Base Class Library).
Theory: The CLR helps in managing memory, executing code, and handling exceptions, while BCL provides
essential built-in functions.
Hello World in C#
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, World!");
}
}
C# Features
• Strongly typed
• Object-oriented
• Automatic memory management (Garbage Collection)
• Rich class libraries
1
Day 2: Data Types and Variables
Theory: In programming, data types define what kind of data a variable can hold. Variables are containers
to store data.
Value Types
• int, float, double, char, bool, struct
Reference Types
• string, object, arrays, classes
Variable Declaration
int age = 30;
string name = "Alice";
bool isMarried = true;
Type Conversion
int x = 10;
double y = x; // Implicit
int z = (int)y; // Explicit
Day 3: Control Statements
Theory: Control statements allow you to make decisions and repeat actions in code.
If-Else
if (x > 0) {
Console.WriteLine("Positive");
} else {
Console.WriteLine("Negative or Zero");
}
2
Switch
switch (day) {
case 1: Console.WriteLine("Monday"); break;
default: Console.WriteLine("Unknown"); break;
}
Loops
• for, while, do-while, foreach
Theory: Loops help in repeating a block of code multiple times. Use for when the number of iterations is
known, and while when it's not.
Day 4: Arrays and Strings
Theory: Arrays store multiple values of the same type. Strings are sequences of characters.
Arrays
int[] numbers = {1, 2, 3, 4};
foreach (int num in numbers) {
Console.WriteLine(num);
}
Strings
string s = "Hello";
Console.WriteLine(s.Length);
Console.WriteLine(s.ToUpper());
Day 5: Object-Oriented Programming (OOP)
Theory: OOP is a way of organizing code using objects, which are instances of classes.
3
Class and Object
class Person {
public string Name;
public void SayHello() {
Console.WriteLine($"Hello, {Name}");
}
}
Inheritance
class Animal {
public void Speak() => Console.WriteLine("Animal sound");
}
class Dog : Animal {}
Polymorphism and Overriding
class Base {
public virtual void Show() => Console.WriteLine("Base");
}
class Derived : Base {
public override void Show() => Console.WriteLine("Derived");
}
Day 6: Encapsulation and Abstraction
Theory: Encapsulation hides the internal state and only exposes necessary parts. Abstraction hides complex
reality while exposing only the essential parts.
Encapsulation
• Use private fields and public properties
Abstraction
• Use abstract classes and interfaces
4
abstract class Shape {
public abstract void Draw();
}
class Circle : Shape {
public override void Draw() => Console.WriteLine("Draw Circle");
}
Day 7: Exception Handling
Theory: Exceptions are errors that occur during program execution. Proper handling avoids crashes and
allows for graceful recovery.
Try-Catch-Finally
try {
int x = 5 / 0;
} catch (DivideByZeroException ex) {
Console.WriteLine("Cannot divide by zero");
} finally {
Console.WriteLine("Done");
}
Throwing Exceptions
throw new InvalidOperationException("Invalid operation");
Day 8: Collections and Generics
Theory: Collections are used to store groups of related objects. Generics allow you to write type-safe and
reusable code.
List
List<int> numbers = new List<int> {1, 2, 3};
5
Dictionary\<TKey, TValue>
Dictionary<string, int> ages = new Dictionary<string, int>();
Generics
class Box<T> {
public T Value;
}
Day 9: LINQ and File I/O
Theory: LINQ (Language Integrated Query) helps you query collections easily. File I/O is for reading/writing
data to files.
LINQ Basics
var result = from n in numbers where n > 2 select n;
File I/O
File.WriteAllText("file.txt", "Hello");
string content = File.ReadAllText("file.txt");
Day 10: Common Interview Questions
1. What is the difference between value and reference types?
2. What is the use of using statement?
3. Explain the concept of garbage collection.
4. What are delegates and events?
5. What is the difference between abstract class and interface ?
6. What is boxing and unboxing?
7. What is the difference between override , new , and virtual ?
6
Final Tips
• Practice small programs daily.
• Revise OOP principles well.
• Understand how collections and exceptions work.
• Be confident in syntax and explain code.
Good luck! You’ve got this!