C# School Ebook: Quick Reference & Practice Exercises

C# School Ebook: From Zero to Intermediate in 8 WeeksLearning C# in eight weeks is an achievable goal with a focused plan, practical exercises, and consistent practice. This ebook-style guide is designed for students and self-learners who start with little or no programming background and want to reach an intermediate level in C# using clear explanations, examples, and projects that build on one another.


Why C#?

C# is a modern, object-oriented programming language developed by Microsoft. It’s widely used for desktop applications with .NET, web backends with ASP.NET Core, game development with Unity, and cross-platform mobile apps with .NET MAUI. Learning C# gives you transferable skills across many areas of software development.


How this ebook is organized

The book is structured into eight weekly modules. Each week contains:

  • Concepts to learn
  • Practical examples with code snippets
  • Short exercises
  • One mini-project or challenge to solidify skills

At the end of the ebook, you’ll find answers to exercises, a recommended reading list, and tips for next steps (advanced topics, tools, and career paths).


Week 1 — Foundations: Getting started with C# and .NET

Goals:

  • Install .NET SDK and a code editor (Visual Studio / VS Code)
  • Understand the anatomy of a C# program
  • Write, compile, and run simple programs

Topics:

  • Setup: .NET SDK, editors, creating projects with dotnet new
  • The Program class, Main method, namespaces
  • Variables, data types (int, double, bool, string), basic I/O (Console.WriteLine, Console.ReadLine)
  • Operators and expressions, simple arithmetic, string interpolation

Example:

using System; class Program {     static void Main()     {         Console.WriteLine("Hello, C# learner!");         Console.Write("Enter your name: ");         string name = Console.ReadLine();         Console.WriteLine($"Welcome, {name}!");     } } 

Exercises:

  • Create a calculator that adds, subtracts, multiplies, and divides two numbers from user input.
  • Write a program that converts Celsius to Fahrenheit.

Mini-project:

  • Build a simple quiz that asks 5 fixed questions and scores the user.

Week 2 — Control flow and collections

Goals:

  • Master conditional statements and loops
  • Learn basic collections: arrays, List

Topics:

  • if, else if, else, switch
  • while, do-while, for, foreach
  • Arrays, Lists, basic List operations (Add, Remove, Count)
  • Introduction to error handling with try/catch

Example:

var numbers = new List<int> {1, 2, 3, 4, 5}; int sum = 0; foreach (var n in numbers) sum += n; Console.WriteLine($"Sum: {sum}"); 

Exercises:

  • Implement a number-guessing game using loops and random numbers.
  • Create and sort an array of integers.

Mini-project:

  • Build a simple task manager console app: add tasks, list tasks, mark done, remove tasks.

Week 3 — Methods, parameters, and basic debugging

Goals:

  • Break code into methods for modularity
  • Understand parameter passing and return values
  • Use debugging tools and write unit-testable code

Topics:

  • Defining methods, method overloading, optional parameters
  • Value types vs reference types
  • Basic debugging in Visual Studio/VS Code: breakpoints, watch, step-over/into
  • Writing simple unit tests with xUnit or NUnit (setup and a few test cases)

Example:

int Add(int a, int b) => a + b; Console.WriteLine(Add(2, 3)); // 5 

Exercises:

  • Refactor the calculator from Week 1 into methods.
  • Write tests for a method that checks whether a string is a palindrome.

Mini-project:

  • Create a small library (class) for operations on a shopping list and write unit tests for it.

Week 4 — Object-Oriented Programming (OOP) basics

Goals:

  • Understand classes, objects, properties, and methods
  • Learn encapsulation and constructors

Topics:

  • Defining classes and creating objects
  • Properties (auto-properties), access modifiers (public, private, protected)
  • Constructors, read-only fields, static members
  • ToString override and simple composition

Example:

class Person {     public string Name { get; set; }     public int Age { get; set; }     public Person(string name, int age) => (Name, Age) = (name, age);     public override string ToString() => $"{Name}, {Age}"; } 

Exercises:

  • Create a Book class and instantiate several books.
  • Implement methods to update and display book info.

Mini-project:

  • Build a simple library system to add, search, and list books (console-based).

Week 5 — Advanced OOP: inheritance, interfaces, and polymorphism

Goals:

  • Use inheritance to share behavior
  • Apply interfaces and abstract classes
  • Understand polymorphism and virtual/override

Topics:

  • Base and derived classes, protected members
  • Abstract classes vs interfaces
  • Virtual methods, overriding, and the is/as operators
  • Dependency inversion basics (constructor injection)

Example:

abstract class Animal {     public abstract void Speak(); } class Dog : Animal {     public override void Speak() => Console.WriteLine("Woof"); } 

Exercises:

  • Model a vehicle hierarchy with Car, Bike, Truck classes.
  • Create an interface ILogger and implement ConsoleLogger and FileLogger.

Mini-project:

  • Build a simple zoo simulation where animals perform actions polymorphically.

Week 6 — Collections in depth, LINQ, and generics

Goals:

  • Use advanced collection types and LINQ for concise data queries
  • Learn generics for reusable code

Topics:

  • Dictionaries, HashSet, Queue, Stack
  • Introduction to generics: generic classes and methods
  • LINQ basics: Where, Select, OrderBy, GroupBy, FirstOrDefault
  • Deferred execution and IEnumerable vs IList

Example:

var people = new List<Person> { new Person("Alice", 30), new Person("Bob", 22) }; var adults = people.Where(p => p.Age >= 18).OrderBy(p => p.Name); foreach (var a in adults) Console.WriteLine(a); 

Exercises:

  • Use LINQ to group a list of words by their first letter.
  • Implement a generic Pair class.

Mini-project:

  • Build a contacts manager supporting search, group-by, and simple filtering using LINQ.

Week 7 — Asynchronous programming and file I/O

Goals:

  • Understand async/await and tasks
  • Read from and write to files

Topics:

  • Task, Task, async methods, await, exception handling in async methods
  • File I/O with System.IO: File.ReadAllTextAsync, File.WriteAllTextAsync, streams
  • CancellationToken basics and simple cancellation patterns
  • Intro to HTTP calls with HttpClient and async I/O

Example:

async Task<string> DownloadAsync(string url) {     using var client = new HttpClient();     return await client.GetStringAsync(url); } 

Exercises:

  • Convert a synchronous file-processing program to async.
  • Write a program that fetches JSON from a URL and displays a parsed field.

Mini-project:

  • Create an async logger that writes messages to a file without blocking the main thread.

Week 8 — Building a complete intermediate project and next steps

Goals:

  • Combine what you’ve learned into a larger project
  • Learn about project structure, NuGet packages, and basic deployment

Topics:

  • Project organization: multiple classes, folders, and namespaces
  • Using NuGet packages and reading package docs
  • Simple configuration with appsettings.json
  • Preparing for deployment or sharing your app (creating a single-file publish, producing a DLL, or sharing source)

Project suggestion (console-to-API evolution):

  • Phase 1 (console): Build a Task/ToDo application with persistence to a local JSON file. Features: create, list, update, delete tasks, search, and tagging.
  • Phase 2 (optional): Wrap core logic into a class library and add a minimal ASP.NET Core Web API frontend to expose tasks over HTTP.
  • Phase 3 (optional): Add a simple UI with Blazor or a Unity front-end for gamified task interaction.

Final exercises:

  • Write documentation (README) for your project.
  • Add unit tests for core business logic and run them.

Appendices

  • Cheat sheet: common C# constructs, keywords, and idioms.
  • Quick reference: LINQ method summaries and common patterns.
  • Recommended tools: Visual Studio, VS Code, Rider; Git; Postman; dotnet CLI.
  • Further reading: Microsoft docs, C# in Depth (Jon Skeet), .NET official docs, community tutorials.
  • Job/portfolio tips: how to present projects, write clean READMEs, and prepare for interviews.

Sample schedule (daily time estimate)

  • Weekdays: 1.5–2 hours/day (read + practice)
  • Weekends: 3–5 hours (project work + review)
  • Total: ~80–120 hours over 8 weeks

Tips for success

  • Code daily — small, consistent practice beats occasional marathon sessions.
  • Build projects — theory sinks in when applied.
  • Use version control — commit often and write helpful messages.
  • Learn to read error messages — debugging is a key skill.
  • Pair learning with community: ask questions on forums, share progress.

This ebook gives a clear, step-by-step path from zero to intermediate C# in eight weeks, focusing on practical learning and progressively challenging projects to build confidence and real-world skills.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *