Guide · C# Programming Language

C# Programming Language – Learning Guide

C# is a modern, object-oriented language from Microsoft and part of the .NET platform. It is used for desktop applications (Windows Forms, WPF), web applications (ASP.NET Core), games in Unity and cloud programs.

The guide leads from the first program in Visual Studio, through variables, loops, methods, classes and collections, to LINQ queries, Windows Forms applications with a database and web applications in ASP.NET Core.

  • Primary and secondary school
  • Beginner and intermediate level
  • Examples in C#
Tip: install the free Visual Studio Community (the ".NET Desktop Development" workload) or the .NET SDK with VS Code. Follow the lessons in order; run every example and change at least one value.

Some lessons linked below are available only in Serbian for now. They are marked (SR).

1 C# basics

The first program, data types, operators, branching, loops, arrays, strings and methods.

2 Object-oriented programming

Classes and objects, properties, inheritance, abstract classes and interfaces.

3 Collections, exceptions and LINQ

Ready-made data structures, error handling and queries over collections.

4 Windows Forms and databases

Applications with windows and data in a database: SQLite, MySQL and SQL Server.

5 Web applications: ASP.NET Core

C# on the server: web pages, routes and working with data. You need classes, collections and web basics.

6 Short examples

Four short programs for a quick start. Detailed explanations are in the lessons above.

A basic C# program:

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello, world!");
    }
}
    

A class and an object:

using System;

class Person
{
    public string Name;

    public void Introduce()
    {
        Console.WriteLine($"Hello, I am {Name}");
    }
}

class Program
{
    static void Main()
    {
        Person p = new Person();
        p.Name = "Ana";
        p.Introduce();
    }
}
    

A list (List<T>):

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };

        foreach (int n in numbers)
            Console.Write(n + " ");
    }
}
    

Task: Write a recursive function that computes the sum of the numbers from 1 to n.

using System;

class Program
{
    static int Sum(int n)
    {
        if (n == 0) return 0;
        return n + Sum(n - 1);
    }

    static void Main()
    {
        Console.WriteLine("The sum of the numbers up to 10 is: " + Sum(10));
    }
}
    

For practice: Additional examples – classes and objects (solutions in C++ and C#, e.g. "Car showroom"). Back to Programming languages.