Since they are equivalent ++ and +1 should compile to the same code, right? As we can see below, this … Continue reading .NET 7 increment operator ++ and +1 compiling differently
Category: C# Blog
C# blog posts covering topics such as usage tips, little known features, new features in upcoming versions of the language, performance tips including BenchmarkDotNet benchmarks and more…
Benchmark custom code workarounds against each new version of .NET as the framework gets faster all the time
Always revisit and benchmark your custom code workarounds with each version of .NET. The .NET framework and the JIT compiler gets faster … Continue reading Benchmark custom code workarounds against each new version of .NET as the framework gets faster all the time
String + versus StringBuilder benchmarks for 50K one char concatenations in .NET 7
I’m sure there’s still some junior .NET devs using + to concatenate large (usually an unknown) amounts of strings? Look … Continue reading String + versus StringBuilder benchmarks for 50K one char concatenations in .NET 7
File scoped types new in C# 11
File scoped types are new in C#11 and allow us to create types whose visibility is scoped to the source … Continue reading File scoped types new in C# 11
C# Explicit Operator example to map from one type to another
In .NET we have plenty of ways to map objects to one another. Below is an example, courtesy of ChatGPT … Continue reading C# Explicit Operator example to map from one type to another
.NET 6 v .NET 7 reflection performance benchmarks
.NET 7 (Preview 5+) has some awesome performance improvements when it comes to reflection functionality like invoking methods BUT there … Continue reading .NET 6 v .NET 7 reflection performance benchmarks
How to run benchmarks against multiple versions of .NET with BenchmarkDotNet
If you’re into this sort of stuff like me it can be fun to run benchmarks against bits of code … Continue reading How to run benchmarks against multiple versions of .NET with BenchmarkDotNet
Regular Expressions using RegexOptions.IgnoreCase slower than inline case insensitive pattern syntax in .NET 6
RegexOptions.IgnoreCase often offers better readability and expression of intent than inline pattern matching. We can see examples of the two … Continue reading Regular Expressions using RegexOptions.IgnoreCase slower than inline case insensitive pattern syntax in .NET 6
Three examples of Regular Expression performance improvements in .NET 7
Stephens Toubs performance articles on devblogs.microsoft.com are always something I look forward to. In May 2022 he wrote one covering … Continue reading Three examples of Regular Expression performance improvements in .NET 7
Favour Boolean assignment via expressions in C# rather than if/else blocks
Where applicable favour Boolean assignment via expressions rather than if/else blocks. The first example below is still so common but … Continue reading Favour Boolean assignment via expressions in C# rather than if/else blocks
Use the digit separator character in C# to improve readability of large numbers
Using the digit separator character _ in C# to break up your large numbers is just another little thing you … Continue reading Use the digit separator character in C# to improve readability of large numbers
Nested ternarys can be hard to read for other developers
Be careful with nested ternarys as they can impact code readability. For example I know what 👇🏻 … var comparison … Continue reading Nested ternarys can be hard to read for other developers
How to get started with BenchmarkDotNet using a simple example
BenchmarkDotNet has become the de facto standard for performance benchmarking on .NET. Nearly every video or blog post which Microsoft … Continue reading How to get started with BenchmarkDotNet using a simple example
Use C# 10 Global Usings to make namespaces available to all files in a project
Global Usings in C# 10 allow us to declare a namespace as being available to all files in a project … Continue reading Use C# 10 Global Usings to make namespaces available to all files in a project
Use file-level namespaces in C# 10 to reduce vertical nesting
In C# 9 we saw how top-level statements can help us reduce ‘wasted’ vertical space… BUT… reducing ‘wasted’ horizontal space … Continue reading Use file-level namespaces in C# 10 to reduce vertical nesting
Consider using named arguments in C# to increase readability of method calls
By using named arguments in C# we don’t have to match the ordering of parameter lists of called methods. Instead the … Continue reading Consider using named arguments in C# to increase readability of method calls
.NET 7 to include new ThrowIfNullOrEmpty ArgumentException guard clause
In .NET 6 Microsoft introduced the ArgumentException.ThrowIfNull guard clause and in .NET 7 (Preview 4) they have introduced ArgumentException.ThrowIfNullOrEmpty. Using … Continue reading .NET 7 to include new ThrowIfNullOrEmpty ArgumentException guard clause
System.Random is much faster in .NET 6 as Microsoft have changed underlying algorithm
In .NET 6 Microsoft have changed the algorithm used in System.Random and the performance improvements are crazy. Check out the … Continue reading System.Random is much faster in .NET 6 as Microsoft have changed underlying algorithm
Microsoft drops parameter null checking operator from C#11
Looks like Microsoft have pulled the null check !! operator from C#11. It had been included in C# 11 early … Continue reading Microsoft drops parameter null checking operator from C#11
Poll Results : Have you used Default Implementations in Interfaces in C# 8+ yet?
Default Implementations in Interfaces were introduced in C#8 and allow us add new members to a public interface without breaking … Continue reading Poll Results : Have you used Default Implementations in Interfaces in C# 8+ yet?
.NET 6 performance improvements when comparing two arrays using SequenceEquals
There’s some pretty impressive performance improvements in .NET 6 when we are comparing arrays using the LINQ SequenceEqual method. The … Continue reading .NET 6 performance improvements when comparing two arrays using SequenceEquals
Amazing performance improvement in .NET 6 when creating one SortedDictionary from another
The performance improvements when cloning one SortedDictionary from another in .NET 6 compared to .NET 5 are amazing. I’m not … Continue reading Amazing performance improvement in .NET 6 when creating one SortedDictionary from another
ImmutableList performance improvements in .NET 6
Another small but welcome performance improvement in .NET 6 is with item retrieval times when using ImmutableList… It looks like … Continue reading ImmutableList performance improvements in .NET 6
How to set the Ratio column style in BenchmarkDotNet results
By default when you output the Ratio column in BenchmarkDotNet using the Baseline = true attribute it is output using … Continue reading How to set the Ratio column style in BenchmarkDotNet results
Using declarations in C#8+ can allow us to dispose of resources correctly without increasing nesting levels
Since C#8 we can use single lineĀ using declarations which will allow us to dispose of resources at the end of … Continue reading Using declarations in C#8+ can allow us to dispose of resources correctly without increasing nesting levels