Levi Zitting Logo

.NET and Why You Should Care

What is .NET?

.NET is an open-source developer platform from Microsoft for building all sorts of applications.

What's a Developer Platform?

  • A developer ecosystem
  • A set of tools and libraries that accelerate the development of your applications

.NET Strikes a Balance Between

  • Productivity
  • Performance
  • Security
  • Reliability

What Can You Do With it?

Web

  • ASP.NET
  • Blazor (Server & WebAssembly)

Mobile

  • Xamarin
  • MAUI

Desktop

  • Blazor Hybrid
  • WinUI and WinAppSDK
  • MAUI

Microservices and Cloud

  • Serverless
  • Designed for Docker

Machine Learning

  • ML.NET
  • Apache Spark

Game Development

  • Unity
  • MonoGame
  • Godot

IoT (Internet of Things)

  • IoT Libraries (including device bindings)
  • Wilderness Labs Meadow Board

.NET Does All of This While Using the Same:

  • Programming languages
  • Libraries
  • Tools and techniques

How Does .NET Do All of This?

Programming Languages

  • Visual Basic
  • F# (F Sharp)
  • C# (C Sharp)

Tooling

  • Base Class Library (BCL)
  • Nuget (package management)
  • Visual Studio (Windows & Mac)
  • Command line tools - dotnet

The Compiler

  • Code Analysis
  • Language Server
  • Type Checking
  • Refactoring/Formatting
  • And of course, compiling
Roslyn compiler logo

Common Intermediate Language (CIL)



.assembly Hello {}
.assembly extern mscorlib {}
.method static void Main()
{
    .entrypoint
    .maxstack 1
    ldstr "Hello, world!"
    call void [mscorlib]System.Console::WriteLine(string)
    ret
}
        

Common Language Runtime (CLR)

  • The .NET virtual machine
  • Just in time (JIT) compilation
  • Memory management/garbage collection
  • Type safety and exception handling

Anatomy of a .NET Project

Files and Layout

  • .csproj - Defines a C# project
    • Build configuration
    • Dependencies
  • .sln - Organizes multiple projects (monorepo)
  • .cs - C# source file
  • obj - Object, or intermediate, files
  • bin - Binary files
A screenshot of a folder tree showing a standard .NET project layout

Assemblies

  • Unit of deployment and versioning
  • Contains compiled code, resources, metadata
  • Can be process assemblies (.exe) or library assemblies (.dll)
  • Can have dependencies on other assemblies
  • Loaded and executed by .NET runtime

A Note on .NET Versions

  • .NET Framework
  • .NET Core
  • A unified .NET (.NET 5+)

C# Syntax


using System;

namespace MyNamespace;

class Program {
    static void Main(string[] args) {
        string message = "Hello, world!"
        // var message = "Hello, world!"
        Console.WriteLine(message);
    }
}
        

C# Syntax - Control Flow


static void Main(string[] args) {
    if (myInt > 10) {
        // do something
    } else {
        // do something else
    }

    foreach (var item in myList) {
        // do something with item
    }

    try {
        // some code that might throw an exception
    } catch (Exception ex) {
        // handle the exception
    }
}
        

C# Syntax - Properties


class Person
{
    private int age;
    public int Age {
        get { return age; }
        set { age = value; }
    }

    public string FirstName { get; set; }
    public string LastName { get; set; }

    public string FullName => $"{FirstName} {LastName}";
}
        

C# Syntax - Inheritance


public class Animal {
    public virtual void MakeSound() {
        Console.WriteLine("The animal makes a sound");
    }
}

public class Cat : Animal {
    public override void MakeSound() {
        Console.WriteLine("The cat meows");
    }
}
        

C# Syntax - Attributes


[Serializable]
public class MyClass {
    [Obsolete("This method is deprecated.")]
    public void MyOldMethod() {
        // do something old
    }
}
        

C# Syntax - Generics


public class MyGenericClass<T> {
    private T[] myArray;

    public MyGenericClass(int size) {
        myArray = new T[size];
    }

    public void SetItem(int index, T item) {
        myArray[index] = item;
    }

    public T GetItem(int index) {
        return myArray[index];
    }
}
        

Demo! 🎉

glitchedmob/dotnet-and-why-you-should-care-demo

So Why Should You Care?

Productivity 🔨

  • Cross platform
  • Covers most application types
  • Large BCL for reusable code
  • Powerful debugging tools

Performance 🔥

  • JIT compilation
  • Native interoperability
  • Multi-threading support

Security 🔒

  • Regular updates
  • Strong Cryptography
  • Sandboxed execution environment

Reliability 🛡️

  • Strong type system
  • Automatic memory management
  • Stable runtime
  • Support from Microsoft

Questions?