Easy Learn C#

Beginner C# Course

Welcome to our interactive C# course for beginners! This course contains 20 progressive exercises that will teach you C# programming from the ground up. Complete the exercises in order to unlock more advanced topics.

0% Complete (0/20)

Module 1: Getting Started with C#

Exercise 1: Hello World

Not Started

Let's start with the classic "Hello World" program. This is often the first program written when learning a new language.

Task: Complete the code below by adding the missing line to display "Hello, World!" to the console.

Hint: Look for the TODO comment and use Console.WriteLine() to output text to the console.

using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            // TODO: Add a line of code here to display "Hello, World!" to the console
            
        }
    }
}
Output:
Code not run yet...
Need a hint?

Replace the TODO comment with this line:

Console.WriteLine("Hello, World!");

Exercise 2: Variables and Output

Locked

Complete previous exercises to unlock this exercise.

Variables are used to store data values. In C#, variables must be declared with a specific data type.

Task: Complete the code by filling in the TODOs:

  1. Create a string variable named name and assign your name to it
  2. Create an integer variable named age and assign your age (or any number) to it
  3. Complete the Console.WriteLine statement to display your name and age
using System;

namespace VariablesAndOutput
{
    class Program
    {
        static void Main(string[] args)
        {
            // TODO 1: Create a string variable named 'name' and assign your name to it
            
            
            // TODO 2: Create an integer variable named 'age' and assign your age to it
            
            
            // TODO 3: Complete the WriteLine statement to display both variables
            Console.WriteLine($"My name is {/* Your code here */} and I am {/* Your code here */} years old.");
        }
    }
}
Output:
Code not run yet...
Need a hint?

Here's how to complete each TODO:

// TODO 1: Create a string variable named 'name' and assign your name to it
string name = "John";

// TODO 2: Create an integer variable named 'age' and assign your age to it
int age = 25;

// TODO 3: Complete the WriteLine statement to display both variables
Console.WriteLine($"My name is {name} and I am {age} years old.");

Exercise 3: Basic Math Operations

Locked

Complete previous exercises to unlock this exercise.

C# supports various arithmetic operations such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).

Task: Complete the code by filling in the TODOs to perform basic math operations and display the results.

using System;

namespace MathOperations
{
    class Program
    {
        static void Main(string[] args)
        {
            // Variables are already declared for you
            int a = 10;
            int b = 3;
            
            // TODO 1: Calculate the sum of a and b and store in a variable named 'sum'
            int sum = // Your code here
            
            // TODO 2: Calculate the difference between a and b (a - b) and store in a variable named 'difference'
            int difference = // Your code here
            
            // TODO 3: Calculate the product of a and b and store in a variable named 'product'
            int product = // Your code here
            
            // TODO 4: Calculate the quotient of a divided by b and store in a variable named 'quotient'
            int quotient = // Your code here
            
            // TODO 5: Calculate the remainder when a is divided by b using the modulus operator and store in a variable named 'remainder'
            int remainder = // Your code here
            
            // The code to display the results is already written for you
            Console.WriteLine($"a = {a}, b = {b}");
            Console.WriteLine($"Sum: {sum}");
            Console.WriteLine($"Difference: {difference}");
            Console.WriteLine($"Product: {product}");
            Console.WriteLine($"Quotient: {quotient}");
            Console.WriteLine($"Remainder: {remainder}");
        }
    }
}
Output:
Code not run yet...
Need a hint?

Here's how to perform each math operation:

// TODO 1: Calculate the sum of a and b and store in a variable named 'sum'
int sum = a + b;

// TODO 2: Calculate the difference between a and b (a - b) and store in a variable named 'difference'
int difference = a - b;

// TODO 3: Calculate the product of a and b and store in a variable named 'product'
int product = a * b;

// TODO 4: Calculate the quotient of a divided by b and store in a variable named 'quotient'
int quotient = a / b;

// TODO 5: Calculate the remainder when a is divided by b using the modulus operator and store in a variable named 'remainder'
int remainder = a % b;

Exercise 4: User Input

Locked

Complete previous exercises to unlock this exercise.

Programs often need to get input from users. In C#, we can use Console.ReadLine() to read user input from the console.

Task: Create a program that:

  1. Asks the user to enter their name
  2. Reads the input using Console.ReadLine()
  3. Asks the user to enter their age
  4. Reads the age input and converts it to an integer using int.Parse()
  5. Calculates what year they were born (roughly) by subtracting their age from the current year
  6. Outputs a personalized message with their name and birth year
using System;

namespace UserInput
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get the current year (for simplicity, we'll hardcode it)
            int currentYear = 2023;
            
            // Ask for user's name
            
            // Read the name input
            
            // Ask for user's age
            
            // Read and convert the age input
            
            // Calculate birth year
            
            // Output personalized message
            
        }
    }
}
Output:
Code not run yet...
Need a hint?

Here's how to get user input and convert it:

Console.Write("Enter your name: ");
string name = Console.ReadLine();

Console.Write("Enter your age: ");
int age = int.Parse(Console.ReadLine());

int birthYear = currentYear - age;
Console.WriteLine($"Hello {name}, you were born around {birthYear}.");

Module 2: Control Flow

Exercise 5: If-Else Statements

Locked

Complete previous exercises to unlock this exercise.

Exercise 6: For Loops

Locked

Complete previous exercises to unlock this exercise.

Exercise 7: While Loops

Locked

Complete previous exercises to unlock this exercise.

Exercise 8: Arrays

Locked

Complete previous exercises to unlock this exercise.

Exercise 9: Methods

Locked

Complete previous exercises to unlock this exercise.

Exercise 10: Simple Calculator

Locked

Complete previous exercises to unlock this exercise.

Module 3: Object-Oriented Programming

Exercise 11: Classes and Objects

Locked

Complete previous exercises to unlock this exercise.

Exercise 12: Lists and LINQ

Locked

Complete previous exercises to unlock this exercise.

Exercise 13: Exception Handling

Locked

Complete previous exercises to unlock this exercise.

Exercise 14: File Handling

Locked

Complete previous exercises to unlock this exercise.

Module 4: Advanced C# Programming

Exercise 15: Inheritance

Locked

Complete previous exercises to unlock this exercise.

Exercise 16: Interfaces

Locked

Complete previous exercises to unlock this exercise.

Exercise 17: Generics

Locked

Complete previous exercises to unlock this exercise.

Exercise 18: Delegates and Events

Locked

Complete previous exercises to unlock this exercise.

Exercise 19: LINQ Basics

Locked

Complete previous exercises to unlock this exercise.

Exercise 20: Asynchronous Programming

Locked

Complete previous exercises to unlock this exercise.