Best of C#April 2026

  1. 1
    Article
    Avatar of devblogsDevBlogs·7w

    Explore union types in C# 15

    C# 15 introduces the `union` keyword in .NET 11 Preview 2, allowing developers to declare a closed set of case types with compiler-enforced exhaustive pattern matching. Unlike object, marker interfaces, or abstract base classes, union types don't require related types and prevent external extension. The compiler generates a struct with implicit conversions from each case type and a `Value` property. Switch expressions over union types are exhaustive without needing a discard arm, and adding a new case type triggers compiler warnings on incomplete switches. Custom union types are also supported via a `[Union]` attribute for existing libraries, including a non-boxing access pattern for performance-sensitive scenarios. Related proposals for closed hierarchies and closed enums round out a comprehensive exhaustiveness story for C#.

  2. 2
    Article
    Avatar of csharpcornerC# Corner·8w

    What is the Difference Between Task and Thread in C#?

    A beginner-friendly comparison of Thread and Task in C#, explaining the key differences in abstraction level, performance, and usability. Uses a restaurant analogy to illustrate how Tasks leverage the .NET Thread Pool for efficiency versus raw OS threads. Covers return values, exception handling, async/await support, cancellation, and guidance on when to use each approach.

  3. 3
    Article
    Avatar of dotnet.NET Blog·6w

    .NET 11 Preview 3 is now available!

    .NET 11 Preview 3 is now available, bringing improvements across the runtime, SDK, libraries, ASP.NET Core, .NET MAUI, C#, Entity Framework Core, and container images. Key highlights include: System.Text.Json gains more naming and default-ignore control; Zstandard compression moves to System.IO.Compression; runtime async removes the preview-API opt-in requirement; JIT optimizations improve switches, bounds checks, and casts; WebAssembly gets WebCIL and debugging improvements; the SDK adds file-based app splitting across files and `dotnet run -e` for passing environment variables; ASP.NET Core adds Zstandard response compression and earlier HTTP/3 request processing; .NET MAUI adds map clustering, XAML startup improvements, and Android 17/API 37 preview support; and EF Core improves SQL generation, migrations, and DbContext configuration.

  4. 4
    Article
    Avatar of milanjovanovicMilan Jovanović·5w

    Why I Switched to Primary Constructors for DI in C#

    C# 12 primary constructors can significantly reduce boilerplate in DI service classes by eliminating field declarations, constructor bodies, and assignments. The author shares their experience switching to primary constructors for ASP.NET Core services, explaining the key pitfall: parameters are captured as mutable variables, not readonly fields, meaning accidental reassignment compiles without warning. The recommended approach is to use primary constructors freely in DI service classes where accidental reassignment is unlikely, but fall back to traditional constructors for validation-heavy types, multiple constructor overloads, or classes with too many dependencies.

  5. 5
    Article
    Avatar of dotnet.NET Blog·5w

    Writing Node.js addons with .NET Native AOT

    The C# Dev Kit team replaced C++ Node.js addons (built with node-gyp and requiring Python) with C# using .NET Native AOT. The post walks through building a Node.js native addon in C# using N-API, covering the project setup, module entry point with [UnmanagedCallersOnly], P/Invoke via [LibraryImport] with a custom DLL resolver pointing to the host process, UTF-8 string marshalling using Span<T> and ArrayPool, and exposing functions to TypeScript. The result eliminated the Python dependency, simplified CI pipelines, and matched C++ performance while opening the door to hosting .NET logic in-process within Node.js.

  6. 6
    Article
    Avatar of andrewlock.NET Escapades·5w

    Removing byte[] allocations in .NET Framework using ReadOnlySpan<T>

    Using `ReadOnlySpan<byte>` properties instead of `static readonly byte[]` fields can eliminate heap allocations entirely — even on .NET Framework — because the compiler embeds the data directly into the assembly metadata. The optimization works only for byte-sized primitives (byte, sbyte, bool) with constant values, and only when returning `ReadOnlySpan<T>` (not `Span<T>`). For other types like `int[]`, the zero-allocation path requires .NET 7+ via `RuntimeHelpers.CreateSpan`. The post walks through the generated IL to confirm the behavior, highlights dangerous edge cases (non-constant values, mutable Span<T>) that silently cause per-access allocations, and notes that collection expressions provide partial compile-time safety for static properties but not local variables.

  7. 7
    Video
    Avatar of freecodecampfreeCodeCamp·5w

    Tired of switching between C# for the back end and JS for the front end?

    Blazor is a Microsoft framework that lets developers build full-stack web applications using C# and HTML, eliminating the need to switch between C# for the backend and JavaScript for the frontend. It uses a component-based architecture similar to React or Vue and comes in two flavors: Blazor WebAssembly (code runs client-side in the browser at near-native speed) and Blazor Server (code stays on the server with UI updates pushed via SignalR). A key advantage is code sharing — DTOs, validation logic, and models can be reused across both client and server.

  8. 8
    Article
    Avatar of collectionsCollections·7w

    .NET 11 Preview 1 and 2: what's new across runtime, Blazor, EF Core, and more

    .NET 11 Previews 1 and 2 introduce Runtime Async V2, which moves async/await state machine logic into the runtime for lower overhead and better diagnostics. Native Zstandard compression is now built into the BCL, offering 2–7x faster decompression than GZip or Brotli. Blazor gains TempData for static SSR, IHostedService support in WebAssembly, a new web worker template, relative URI navigation, built-in form label components, an Environment component, a BasePath component, and simplified SignalR configuration. EF Core adds native SQL Server vector search via LINQ with DiskANN indexes. Additional highlights include BFloat16 support for ML, native OpenTelemetry tracing in ASP.NET Core, up to 17% smaller SDK container images, MAUI/Android improvements with CoreCLR as the default runtime, and CLI enhancements.

  9. 9
    Article
    Avatar of wearedotnetWe Are .NET·4w

    ConfigurationIgnoreAttribute in .NET 11

    NET 11 introduces ConfigurationIgnoreAttribute in Microsoft.Extensions.Configuration, filling a long-standing gap where there was no official way to prevent the configuration binder from populating a specific property. Previously, developers had to use a hacky workaround with ConfigurationKeyNameAttribute and a garbage key name. The new attribute is simple to use — just decorate any property you want excluded from binding. Common use cases include computed/derived properties and parsed representations of raw config values. Note that JsonIgnoreAttribute has no effect on the configuration binder and cannot be used as a substitute.

  10. 10
    Video
    Avatar of nickchapsasNick Chapsas·5w

    .NET Scripting is Finally Complete

    .NET 11 Preview 3 introduces the #include directive for file-based apps, enabling multi-file scripting without a full project setup. This feature, which will also be backported to .NET 10 LTS, allows developers to split code across multiple files during rapid prototyping. Two experimental flags must be enabled: one for the include directive itself and another for transitive (nested) includes. The goal is to bridge the gap between quick single-file scripting and graduating into a full C# project.

  11. 11
    Article
    Avatar of vsVisual Studio Blog·5w

    From AI to .NET: 20 VS Live! Las Vegas Sessions You Can Watch Now

    Microsoft has published 20 sessions from VS Live! Las Vegas 2026 on the Visual Studio YouTube channel, releasing approximately two per day. Topics covered include AI-assisted development with GitHub Copilot, modern .NET and C#, cloud-native apps on Azure, developer productivity, and real-world architecture. Notable sessions include keynotes on Visual Studio 2027 and AI applications, plus talks on ASP.NET Core, GitHub Actions, caching in .NET, and VS Code integration. Upcoming in-person VS Live! events are scheduled through 2027, with discounts available for Visual Studio subscribers.