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#
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.
Introduction to C# (SR)
How the language was created, what it is used for and how it compares with Java, C++ and Python.
Open lesson →The first application (SR)
Installing Visual Studio, a console project, Hello World.
Open lesson →Data and operators (SR)
Types, variables, input (ReadLine, Parse, TryParse) and formatted output.
Open lesson →Branching and loops (SR)
if, switch and the switch expression, for, while, do-while and foreach.
Open lesson →Arrays and strings (SR)
Arrays and matrices, the Array class, string methods, StringBuilder.
Open lesson →Methods (SR)
Parameters and return values, ref and out, overloading, recursion.
Open lesson →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.
Collections (SR)
List, Dictionary, HashSet, Queue and Stack.
Open lesson →Exceptions (SR)
try, catch, finally, throw and your own exceptions.
Open lesson →LINQ and lambda expressions (SR)
Where, Select, OrderBy, GroupBy and lambda expressions.
Open lesson →Advanced example: passengers on a train (SR)
Classes, an interface, a custom exception, an indexer and sorting in one project.
Open lesson →4 Windows Forms and databases
Applications with windows and data in a database: SQLite, MySQL and SQL Server.
Windows Forms and SQLite (SR)
A form for entering users, a connection to the database, display in a DataGridView.
Open lesson →Windows Forms and MySQL (SR)
An example of a car showroom with a MySQL database.
Open lesson →Windows Forms and SQL Server (SR)
The same example with a SQL Server database: adding, showing and deleting.
Open lesson →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.
