C#
Overview
C# is a modern, statically typed, object-oriented language for the .NET platform. It is compiled by Roslyn (the open-source .NET compiler platform, which also exposes rich code-analysis APIs) and runs on the cross-platform .NET runtime. It is used for web (ASP.NET Core), desktop, mobile (MAUI), cloud, and game development. Read this for OOP fundamentals, async/await, LINQ, and the dotnet CLI.
Official sources
Install / setup
Install the .NET SDK from https://dotnet.microsoft.com/download. Then create and run a console project (per https://learn.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code):
dotnet new console -o HelloWorld
cd HelloWorld
dotnet run
Core concepts
- Classes, structs, and records: reference types (
class), value types (struct), and record types for concise immutable data with value equality.
- Static typing with type inference:
var infers the compile-time type; generics provide type-safe collections and APIs.
- Properties and access modifiers: encapsulate fields with auto-properties;
public/private/protected/internal control visibility.
- async/await: the Task-based asynchronous pattern for non-blocking I/O;
async methods return Task/Task<T>.
- LINQ: language-integrated query over collections and other sources, using query or method syntax.
- Nullable reference types: opt-in compiler analysis (
string?) that flags potential null dereferences.
- Exceptions and
using: structured error handling via try/catch/finally; using disposes IDisposable resources deterministically.
Best practices
- Enable nullable reference types and address compiler nullability warnings to avoid
NullReferenceException.
- Use
async/await for I/O-bound work and avoid blocking on tasks (e.g. .Result/.Wait()), which can deadlock.
- Dispose
IDisposable resources with using declarations/statements rather than manual cleanup.
- Prefer LINQ and immutable
record types for clear, declarative data handling.
Common pitfalls
- Blocking on async code with
.Result or .Wait() → can deadlock and wastes threads; await instead, all the way up.
- Dereferencing null references → enable nullable reference types and handle
null at boundaries.
- Forgetting to dispose resources (streams, connections) → use
using to release them deterministically.
- Catching
Exception broadly and swallowing it → catch specific exceptions and let unexpected ones propagate.
Examples
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using var client = new HttpClient();
string body = await client.GetStringAsync("https://example.com");
Console.WriteLine(body.Length);
}
}
Further reading
Related skills
- ../java — another statically typed, object-oriented, VM-hosted language
1---2name: csharp3description: Modern .NET object-oriented language compiled by Roslyn; consult for OOP, async/await, LINQ, and the dotnet CLI.4domain: language5category: language6tags: [csharp, dotnet, roslyn, async, linq]7official_sources:8 - https://learn.microsoft.com/en-us/dotnet/csharp/9 - https://github.com/dotnet/roslyn10 - https://dotnet.microsoft.com/download11verified: 2026-06-1612metadata:13 source: https://skillmd.com/skills/gabriel7silva/csharp14---1516# C#1718## Overview19C# is a modern, statically typed, object-oriented language for the .NET platform. It is compiled by Roslyn (the open-source .NET compiler platform, which also exposes rich code-analysis APIs) and runs on the cross-platform .NET runtime. It is used for web (ASP.NET Core), desktop, mobile (MAUI), cloud, and game development. Read this for OOP fundamentals, async/await, LINQ, and the dotnet CLI.2021## Official sources22- Docs: https://learn.microsoft.com/en-us/dotnet/csharp/23- Repo (Roslyn compiler): https://github.com/dotnet/roslyn24- Install / download (.NET SDK): https://dotnet.microsoft.com/download2526## Install / setup27Install the .NET SDK from https://dotnet.microsoft.com/download. Then create and run a console project (per https://learn.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code):28```bash29dotnet new console -o HelloWorld30cd HelloWorld31dotnet run32```3334## Core concepts35- Classes, structs, and records: reference types (`class`), value types (`struct`), and `record` types for concise immutable data with value equality.36- Static typing with type inference: `var` infers the compile-time type; generics provide type-safe collections and APIs.37- Properties and access modifiers: encapsulate fields with auto-properties; `public`/`private`/`protected`/`internal` control visibility.38- async/await: the Task-based asynchronous pattern for non-blocking I/O; `async` methods return `Task`/`Task<T>`.39- LINQ: language-integrated query over collections and other sources, using query or method syntax.40- Nullable reference types: opt-in compiler analysis (`string?`) that flags potential null dereferences.41- Exceptions and `using`: structured error handling via `try`/`catch`/`finally`; `using` disposes `IDisposable` resources deterministically.4243## Best practices44- Enable nullable reference types and address compiler nullability warnings to avoid `NullReferenceException`.45- Use `async`/`await` for I/O-bound work and avoid blocking on tasks (e.g. `.Result`/`.Wait()`), which can deadlock.46- Dispose `IDisposable` resources with `using` declarations/statements rather than manual cleanup.47- Prefer LINQ and immutable `record` types for clear, declarative data handling.4849## Common pitfalls50- Blocking on async code with `.Result` or `.Wait()` → can deadlock and wastes threads; `await` instead, all the way up.51- Dereferencing null references → enable nullable reference types and handle `null` at boundaries.52- Forgetting to dispose resources (streams, connections) → use `using` to release them deterministically.53- Catching `Exception` broadly and swallowing it → catch specific exceptions and let unexpected ones propagate.5455## Examples56```csharp57using System;58using System.Net.Http;59using System.Threading.Tasks;6061class Program62{63 static async Task Main()64 {65 using var client = new HttpClient();66 string body = await client.GetStringAsync("https://example.com");67 Console.WriteLine(body.Length);68 }69}70```7172## Further reading73- A tour of C#: https://learn.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/overview74- C# language reference: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/7576## Related skills77- ../java — another statically typed, object-oriented, VM-hosted language