Introduction to .NET
.NET is a free, cross-platform, open-source developer platform for building many different types of applications. With .NET, you can use multiple languages, editors, and libraries to build for web, mobile, desktop, games, IoT, and more.
Why .NET?
- Cross-platform: Build and run on Windows, Linux, and macOS
- High performance: One of the fastest web frameworks available
- Unified platform: One SDK for all application types
- Strong ecosystem: Rich libraries and active community
Your First C# Program
Create a simple console application:
// Program.cs
Console.WriteLine("Hello, .NET World!");
// Using top-level statements (C# 9+)
// No Main method required!
Creating a New Project
# Create a new console application
dotnet new console -n MyFirstApp
# Navigate to the project
cd MyFirstApp
# Run the application
dotnet run
C# Language Features
Modern C# includes powerful features:
// Records for immutable data
public record Person(string Name, int Age);
// Pattern matching
var message = person switch
{
{ Age: < 18 } => "Minor",
{ Age: >= 18 and < 65 } => "Adult",
_ => "Senior"
};
// Null-conditional and null-coalescing
string? name = person?.Name ?? "Unknown";
// LINQ for data manipulation
var adults = people.Where(p => p.Age >= 18)
.OrderBy(p => p.Name)
.ToList();
Next Steps
- Learn C# basics: variables, types, and operators
- Understand object-oriented programming in C#
- Explore async/await for asynchronous programming
- Build your first web API with ASP.NET Core