CodeBlanks Logo Icon CodeBlanks

Summary - C# basics

C# course · Beginner · Lesson 6/116

Combine Main, WriteLine and comments to write your first C# program.

Summary

In this unit you learned the basics of C#:

  • C# is a type-safe language that runs on .NET
  • The Main method is the program's entry point
  • Console.WriteLine prints output to the screen
  • // and /* */ write comments
  • $"..." performs string interpolation

Now let's combine these to build small applications.

Exercise First mini app

Add a Console.WriteLine line inside the empty Main. The output must be Hello C#.

Show example solution
Inside Main add Console.WriteLine("Hello C#");.
Example solution:
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello C#");
    }
}

Exercise Second mini app

Use string interpolation to produce Result: 5. Embed the {2 + 3} expression.

Show example solution
{2 + 3}");.
Example solution:
using System;

class Program
{
    static void Main()
    {
        // Print the result with interpolation
        Console.WriteLine($"Result: {2 + 3}");
    }
}

Test yourself

  1. Importing a namespace

    using ____;
    Show answer
    using System;
  2. Summary matching

    Console.WriteLine
    Prints a line
    //
    Single-line comment
    $"
    Interpolation prefix
    Main
    Entry point

All lessons in Beginner