C#
12 posts tagged “C#”.
August 2026
-
Parse text without allocating with Span<T>
Splitting a line with
string.Splitcreates a new string for every field. For large files,ReadOnlySpan<char>lets you parse the same data with almost no allocations.
July 2026
-
Pattern matching that reads like the business rule
Switch expressions, property patterns and list patterns can turn a page of nested ifs into a few lines that read like the requirements. Here are the forms worth knowing.
June 2026
-
Test time-dependent code with TimeProvider
Code that calls
DateTime.UtcNowdirectly is hard to test. Since .NET 8,TimeProvidergives you a standard abstraction, and a fake one that you can move forward on demand.
May 2026
-
Do you still need ConfigureAwait(false)?
In ASP.NET Core application code, no. In libraries, yes. Here's why the answer depends on where your code runs.
April 2026
-
Primary constructors and their surprises
Primary constructors on classes save a lot of boilerplate for dependency injection. Their parameters aren't readonly fields, though, and that has consequences.
March 2026
-
Exceptions or results for expected failures?
"Customer not found" isn't exceptional, but most .NET code throws for it anyway. A simple result type makes expected failures part of the method's signature.
-
Stream results with IAsyncEnumerable
Loading 100,000 rows into a list before sending the first one wastes memory and time.
IAsyncEnumerable<T>lets you process and return items as they arrive.
February 2026
-
Stop using async void and fire-and-forget
async voidcan crash your process, and_ = Task.Run(...)in a web request quietly loses errors and uses disposed services. Here's what to do instead.
January 2026
-
Value objects with C# records
Replacing a
decimaland astringwith aMoneytype removes a whole class of bugs. Records make value objects short to write, with one catch aroundwithexpressions. -
Turning on nullable reference types in an existing codebase
Nullable reference types catch null reference exceptions at compile time. Switching them on in a large, older project produces thousands of warnings. Here's how to adopt them one step at a time.
December 2025
-
ValueTask: when to use it and when not to
ValueTask<T>can save an allocation on hot paths. It also comes with rules thatTaskdoesn't have, and breaking them causes bugs that are hard to trace.
October 2025
-
Records vs classes in C#
Records give you value equality,
withexpressions and a one-line declaration. Here's when that helps, and the two places it quietly bites.