.NET Basics
What is .NET?
.NET is a free, cross-platform, open-source developer platform for building many different types of applications. It provides a comprehensive ecosystem for developing applications that can run on Windows, Linux, macOS, iOS, Android, and more.
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)
.NET Standard
- Formal specification of .NET APIs
- Ensures compatibility across implementations
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
- Use .NET 6+ for new projects: Modern, cross-platform, and well-supported
- Follow naming conventions: PascalCase for classes, camelCase for variables
- Leverage async/await: For I/O-bound operations
- Use dependency injection: Built-in support in .NET Core
- Write unit tests: xUnit, NUnit, or MSTest
- Follow SOLID principles: Object-oriented design principles