Introduction to C# and .NET

Overview

  • C#
  • .NET
  • Common Language Infrastructure (CLI)
  • Base Class Library (BCL)

C#

  • The C# (pronounced c sharp) programming language was introduced by Microsoft in 2000, alongside the .NET framework
  • Unlike C and C++, C# runs on a virtual machine like Java
  • Easy to understand, general purpose, high-level, object oriented
  • Resembles Java, which was very popular in the 90s
  • Newest version is 13.0 from 2024

C# Syntax example

using System;

namespace MyAwesomeProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
  • Everything is inside a class
  • Rows = statements
  • Curly braces { and } mark the start and the end of different bodies of statements
  • Semicolon ; at the end of some statements
  • When to use semicolon? Don't worry: Visual Studio will tell you

.NET

  • .NET (pronounced dot net) is Microsoft's software framework for building and running web services
  • Fully supports C#, F# and Visual Basic
  • Implements Common Language Infrastructure, so it can compile managed code (languages above) into machine code
  • Provides automatic memory management via a garbage collector (GC)
  • Type-safe and memory-safe thanks to GC and strict compilers
  • Uses the NuGet package manager for distributing software (compare to npm in JS)

.NET vs .NET Framework

  • .NET Framework
    • Launched in 2001
    • Closed-source
    • Windows-only
    • Current version 4.8.1 launched in 2022
  • .NET (originally .NET core)
    • Launched in 2016, Successor to .NET Framework
    • Open source
    • Cross-platform (Linux, Mac, Windows)
    • Current version 9.0 launched in 2024
  • We will be using .NET Core as the .NET Framework is considered legacy

Common Language Infrastructure (CLI)

  • Common Language Infrastructure (CLI) is a standardized specification that decribes how different high-level langauges (like C#) can be run on different platforms without having to be rewritten
  • both versions of .NET are implementations of the CLI
  • Another implementation is the free and open-source Mono project
    • Used by the Unity game engine and the MonoGame framework

Base Class Library (BCL)

  • Base Class Library (BCL) is a set of libraries that every .NET implementation uses, mostly under the System namespace
  • Consists of common tools like classes and value types that you will need to create your programs
  • No need to reinvent the wheel with every new project
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    

Assignments

Assignments about this topic can be found here