Introduction to C#: A Beginner's Guide

13 minutes

Table of Contents

In this article, we will introduce you to the C# programming languageā€”its syntax, features, and use cases. If you are unfamiliar with C# I suggest you read this article to understand what the language is before you run off and start on your first Hello, World! program. I know it is tempting to jump ahead into the code, but stay with us.

The concepts and terms thrown at you in this article in a rapid fire fashion may seem at first to be hieroglyphics if you have just picked up C#. Rest assured though that subsequent articles will explain everything in detail.

The C# language

C# is high-level general purpose object-oriented programming language from Microsoft Corporation (MSFT) that was introduced to the public twenty five years ago in 2000, and reached 1.0 status in 2002. It was the brainchild of Anders Hejlsberg, and is currently under the stewardship of Mads Torgersen, who has taken up the torch of leading the C# language development.

The syntax and feature set of C# takes inspiration and builds upon older languages such as Java, C++ and C. The C# language itself would be of little use however without a compilation and execution framework, and that is where the Common Language Infrastructure (CLI) comes in to play. Not to be confused with a Command Line Interface, the CLI is an ECMA-335 standard which outlines the architecture for the runtime environment that allows multiple high-level languages to be executed on computer architectures and platforms without being rewritten.

It also defines features such as a common type system, metadata, Intermediate Language (IL) code, and a Just-In-Time (JIT) compiler. All of these enable interoperability between languages that target the CLI. In the case of C# that means that you could also have interoperability with other Microsoft languages such as Visual Basic and F#.

C# version history

At the time of writing, C# is at version 13.0. Whilst versions of C# were released along with the .NET Framework every two to three years since its release, by C# 9.0 the cadence was increased to November each year.

List of C# versions as of 2025

C# versionRelease date.NET version
1.0January 2002.NET Framework 1.0
1.1April 2003.NET Framework 1.1
1.2April 2003.NET Framework 1.1
2.0November 2005.NET Framework 2.0
3.0November 2007.NET Framework 3.0
.NET Framework 3.5
4.0April 2010.NET Framework 4.0
5.0August 2012.NET Framework 4.5
6.0July 2015.NET Framework 4.6
.NET Core 1.0
.NET Core 1.1
7.0March 2017.NET Framework 4.7
7.1August 2017.NET Core 2.0
7.2November 2017.NET Core 2.0
7.3May 2018.NET Framework 4.8
.NET Core 2.1
.NET Core 2.2
8.0September 2019.NET Core 3.0
.NET Core 3.1
9.0November 2020.NET 5.0
10.0November 2021.NET 6.0
11.0November 2022.NET 7.0
12.0November 2023.NET 8.0
13.0November 2024.NET 9.0

Features of C#

At a high level, C# is a highly flexible, battle-tested, and robust language, making it well-suited for tackling a wide range of programming challenges.

C# high-level features

  • Asynchronous Programming - Async/Await for non-blocking operations.
  • Attributes - Metadata annotations for classes, methods, and properties.
  • Delegates and Events - Function pointers and event-driven programming.
  • Dynamic Binding - dynamic keyword for runtime type resolution.
  • Exception Handling - Try, catch, and finally blocks for error handling.
  • File I/O - Built-in support for reading/writing files.
  • Garbage Collection - Automatic memory management.
  • Generics - Type-safe data structures and methods.
  • Interoperability - Interaction with unmanaged code (P/Invoke, COM).
  • LINQ - Language Integrated Query for data manipulation.
  • Nullable Reference Types - Helps prevent null reference exceptions.
  • Object-Oriented - Supports encapsulation, inheritance, and polymorphism.
  • Pattern Matching - Enhanced pattern matching in switch expressions.
  • Properties and Indexers - Encapsulated field access.
  • Records - Immutable reference types with built-in equality.
  • Reflection - Inspect and manipulate metadata at runtime.
  • Strongly Typed - Enforces type safety at compile time.
  • Threading and Parallelism - Multi-threading with Task and Parallel APIs.
  • Tuples - Lightweight data structures for returning multiple values.
  • Unsafe Code - Pointer-based programming for performance-critical applications.

Understanding the Syntax of C#

As mentioned earlier, the syntax of C# was heavily influenced by the likes of C, C++ and Java. That similarity means that any developers of those languages would be able to pick up passable C# with minimal effort.

Each C# program is organized into classes, interfaces, records & structs. Methods represent actions, while properties and fields represent data. When it comes to running or executing a program written in C#, you will often see a class named Program, with a method named Main, which is the common entrypoint for C# programs. Newer versions of C# and the .NET Framework support a feature named top-level statements, which allow you to forgo the main method entirely, and write your programs at the "top-level" of the file.

Example of a standard C# program with a Main method

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");
    }
}

In this simple example, the using keyword includes namespaces containing classes you wish to reference. System contains many of the common essential classes such as Console, which allows you to output text to a terminal or command-line interface.

Example of a C# program using top-level statements

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

As you can see with the top-level statement example program, you can forgo defining the Program class and Main method entirely. For smaller programs, it is ideal, as you are not distracted by the boilerplate code. You can concentrate your brain space on what is important.

More about C# syntax

C#'s syntax requires statements to end with semicolons ; and curly braces {} to denote the scope of namespaces, classes, methods, loops, conditionals, etc.

C# uses what's called a strongly typed system for variables, which means you need to specify what kind of data you are storing upfront. For example, if you want to keep track of someone's age in years, you would declare it as an integer, as integers in C# can store positive and negative non-decimal numbers. Alternatively, a person's name would be better be declared in a string, as strings are used to store textual information, including alphabetical characters.

By clearly defining the types upfront, C# helps reduce errors and makes your code safer and easier to maintain. An example of that is to think of making a signup form that asks users for the date of their birth. In C#, if you accidentally mix up text and dates, the language will immediately point out the issue for you to correct it before you can compile the program. That quick heads-up will stop small mistakes from turning into bigger headaches later on, keeping your code clean and easy to manage.

C# also provides several shorthand features designed to reduce repetitive code or boilerplate that you would find in other program languages such as Java. For example, when you're initializing new objects or defining properties, C# offers concise ways to simplify the process, such as auto-properties and initializers. These shorthand approaches keep your code tidy, readable, and help you express your ideas clearly without unnecessary clutter.

Supported programming paradigms in C#

C# is what is known as both an imperative and declarative programming language. You might hear the imperative or declarative terms thrown about and feel all-wise when you tell your friends, whilst secretly wondering in the back of your mind what in the world imperative and declarative mean exactly. Do not worry, we got you!

Imperative programming languages are languages which use statements to change a program's state. Think of imperative programming as defining the steps how you will accomplish a goal.

Declarative languages on the other hand express the desired result of the computation, essentially what you want accomplished, without making you provide those pesky step by step instruction statements, which clutter up your IDE and brain space.

Hold up, how can C# be both imperative and declarative?

So how can C# be both imperative and declarative you may ask? That comes down to great work the C# team did with the language design, and the fantastic addition of Language Integrated Query (LINQ) to C# in 2007 and C# 3.0. We will explore LINQ in a future article in detail.

In the meantime, here are two examples of imperative and declarative code in C#, which provide a summation of all of the even numbers in a list.

Again, do not worry if the code is not making sense at this time, as we will guide you through it, and you will get a deeper understanding of how it works as you go through future articles in this series.

Imperative C# example

List<int> numbers = [1, 2, 3, 4, 4, 5];

int evenNumberTotal = 0;

for (int n = 0; n < numbers.Count; n++)
{
    int number = numbers[n];
    if (number % 2 == 0)
    {
        evenNumberTotal += number;
    }
}

The code block above takes a list of numbers, loops through the each number in a list, and for each iteration of the loop, if the modulo 2 operation remainder is zero, the even number total will be incremented by the value of that number.

Therefore, if you had the numbers 1 2 3, 4, 4 and 5, and you performed a modulo operation on each by 2, and added up all those with no remainder, those even numbers added together would equal 10.

Declarative C# example

List<int> numbers = [1, 2, 3, 4, 4, 5];

int evenNumberTotal = numbers
    .Where(number => number % 2 == 0)
    .Sum();

The declarative example above also results in the answer of 10, although how it is done is declarative, and using the what you want method, not how. In this example we are looking for numbers that match the expression number => number % 2 == 0 which you saw in the imperative example as well. Then with those numbers we are directing for the summation of the even numbers to be stored in evenNumberTotal variable.

In many cases, the declarative style is easier to read and interpret, as the cognitive complexity is low and the simplicity is higher.

Supporting both imperative and declarative styles however allows programmers of C# the flexibility to tailor their programs by using a mixture of both declarative and imperative programming styles against the problem they are trying to solve. Some parts of a program may lend itself to the imperative style, and others to the declarative style of programming. Having the freedom to choose the most efficient paradigm for each situation is a significant advantage for skilled developers.

What is C# Used For?

You can find C# used in everything from web development, mobile development, game development, enterprise software, desktop software, cloud computing, AI and machine learning, internet of things (IoT), embedded systems, and augmented reality (AR) and virtual reality (VR) to name a few.

Industry-specific implementation examples for C#

AI and Machine Learning

  • Cognitive Services integrations
  • Convolutional Neural Networks with CNTK
  • Machine Learning applications
  • TensorFlow implementations

Augmented Reality (AR) and Virtual Reality (VR)

  • Microsoft HoloLens applications
  • MRTK implementations
  • Unity VR experiences
  • Windows Mixed Reality applications

Cloud Computing

  • AWS Lambda functions with .NET Core
  • Azure Functions
  • Azure Container Apps
  • Azure Web Apps
  • Microservices on Azure Service Fabric

Desktop Software

  • .NET MAUI applications
  • UWP applications
  • Windows Forms applications
  • WPF desktop applications

Embedded Systems

  • Automotive system interfaces
  • Industry control systems
  • Meadow F7 microcontroller projects
  • Wilderness Labs solutions

Enterprise Software

  • Custom ERP solutions
  • Financial management systems
  • Line-of-business applications
  • Microsoft Dynamics 365

Game Development

  • Godot engine games using C# scripting
  • MonoGame framework projects
  • Unity game engine games
  • XNA Framework games (older)

Internet of Things (IoT)

  • .NET IoT library applications
  • Azure IoT Hub integration
  • Smart home device controllers
  • Windows 10 IoT Core devices

Mobile Development

  • .NET MAUI cross-platform applications
  • Windows Phone applications (historical)
  • Xamarin apps for iOS and Android

Web Development

  • ASP.NET Core applications
  • Blazor websites
  • Content management such as Umbraco
  • E-commerce platforms
  • Endless website and API projects

In conclusion

C# is a highly popular programming language, and jobs requiring C# skills are in high demand in the corporate world. You will not go wrong learning C#, and the skills you will pick up can be applied to a myriad of other programming languages and frameworks used in the industry.

I hope you stay on board for the journey, and above all, enjoy the ride!


Filed under Fundamentals, and tagged under Core Concepts

View the source code for this article on GitHub