Skip to main content

.NET Basics

Key Components

.NET Runtime (CLR - Common Language Runtime)

  • Just-In-Time (JIT) Compilation: Converts Intermediate Language (IL) code to native machine code at runtime
  • Garbage Collection: Automatic memory management
  • Type Safety: Ensures type safety and security
  • Exception Handling: Built-in exception management

Base Class Library (BCL)

  • Provides fundamental classes and types
  • Collections, I/O, networking, threading, and more
  • Consistent API across all .NET implementations

Languages

  • C#: Primary language, modern and object-oriented
  • F#: Functional-first programming language
  • VB.NET: Visual Basic for .NET

.NET Implementations

.NET Framework

  • Original .NET implementation
  • Windows-only
  • Mature and stable

.NET Core / .NET 5+

  • Cross-platform
  • Open-source
  • Modern and high-performance
  • Unified platform (since .NET 5)

Project Types

  • Console Applications: Command-line applications
  • Web Applications: ASP.NET Core for web APIs and MVC
  • Desktop Applications: WPF, WinForms, MAUI
  • Mobile Applications: Xamarin, .NET MAUI
  • Microservices: Lightweight, scalable services
  • Cloud Applications: Azure, AWS integration

Key Features

Cross-Platform

  • Write once, run anywhere
  • Supports Windows, Linux, macOS

High Performance

  • Optimized runtime
  • Ahead-of-Time (AOT) compilation options
  • Minimal memory footprint

Modern Language Features

  • Async/await for asynchronous programming
  • LINQ for data querying
  • Pattern matching
  • Nullable reference types

Rich Ecosystem

  • NuGet package manager
  • Extensive libraries and frameworks
  • Active community support

Getting Started

Installation

# Install .NET SDK
dotnet --version

# Create a new project
dotnet new console -n MyApp

# Run the application
dotnet run

Project Structure

MyApp/
├── Program.cs # Entry point
├── MyApp.csproj # Project file
└── bin/ # Build output

Common Commands

# Create new project
dotnet new <template>

# Restore packages
dotnet restore

# Build project
dotnet build

# Run application
dotnet run

# Add package
dotnet add package <PackageName>

# Publish application
dotnet publish

Version History

  • .NET Framework 1.0 (2002): Initial release
  • .NET Core 1.0 (2016): Cross-platform implementation
  • .NET 5 (2020): Unified platform
  • .NET 6 (2021): Long-term support (LTS)
  • .NET 7 (2022): Performance improvements
  • .NET 8 (2023): Latest LTS version

Best Practices

  1. Use .NET 6+ for new projects: Modern, cross-platform, and well-supported
  2. Follow naming conventions: PascalCase for classes, camelCase for variables
  3. Leverage async/await: For I/O-bound operations
  4. Use dependency injection: Built-in support in .NET Core
  5. Write unit tests: xUnit, NUnit, or MSTest
  6. Follow SOLID principles: Object-oriented design principles

Resources