Category: C#
C# 11 static abstract members
C# 11 is currently proposing in preview interface members declared as static abstract. This is useful to handle both: Polymorphism at the type level, for example when abstracting the concept...
C# async await explained
In 2012, C#5 was released. This version introduced two new keywords async and await. At that time CPU clock speed reached an upper limit imposed by physical laws. But chip...
C# Pattern Matching Explained
Since the C# version 7, C# has support for pattern matching. C# pattern matching is here to simplify complex if-else statements into more compact and readable code. Pattern matching does...
Improve C# code performance with Span<T>
C# 7.2 introduced the structure System.Span<T>. First we’ll present a concrete example where Span<T> helps achieve better performance. Then we’ll explain what makes Span<T> so special. Span<T> primary goal is...
C# Binary Search: Fast find of a free slot between 0 and uint.MaxValue
When a user is exporting a result to a document with NDepend, the tool needs to find a file name not taken in the temporary dir. Generating a GUID for...
Modern C# Hello World
With Visual Studio 2022 when you create a new console project based on .NET 6, the Hello World source code generated is now as simple as that: [crayon-62be9907eb513858779092/] Nice and...
Top 10 New .NET 6.0 API
.NET 6 introduces new handy APIs that will make our development journey easier. Let’s go through the top 10 new API in terms of usage likelyhood. Then in the conclusion,...
How to Logically Name Embedded Resources in .csproj?
You can work with .NET for two decades and still discover some useful stuff. One thing that bothered me till now is that an embedded resource name is “the project...
Migrating Delegate.BeginInvoke Calls to .NET Core, .NET 5 and .NET 6
In this 2019 post, the .NET Base Class Library engineers announced that the good old Delegate.BeginInvoke .NET Framework syntax wasn’t supported in .NET Core and consequently in .NET 5, 6...
Covariance and Contravariance in C# Explained
Introduction This article explains and demonstrates the concepts of Covariance and Contravariance in C# .NET. These concepts will be first introduced for generics, then for delegates and finally for arrays....
Clean Architecture Refactoring: A Case Study
Introduction to Clean Architecture The recent post Clean Architecture for ASP.NET Core Solution: A Case Study explained that one of the most interesting property promoted by Clean Architecture is the...
Hungarian Notation for Fields in C#
If there is one topic that divides the C# developers community, it is the Hungarian notation for fields. In our team we rely on Hungarian notation for fields, not just...
8 Books to Improve as a .NET Developer
Nowadays all information a developer needs to know is available online for free. Blogposts and videos authored by experts, giant questions and answers websites, a quick search and you get...
Clean Architecture for ASP.NET Core Solution: A Case Study
In this post I’ll explore the Jason Taylor’s CleanArchitecture .NET solution template available here on github. It constitutes a good template and it is based on several modern industry wide...
How we quickly refactored with Resharper more than 23.000 calls to Debug.Assert() into more meaningful assertions
Since the NDepend inception more than 15 years ago, we stuffed our code with calls to Debug.Assert(). This results today in more than 23.000 assertions calls. Few developers realize that...
The proper usages of Exceptions in C#
The C# exception basics are generally well understood. However exceptions are often used as a way to sweep error handling duty under the carpet. As I did in The proper...
The proper usages of the keyword ‘static’ in C#
The keyword static is somewhat awkward in a pure Oriented-Object world. I would like to explain here what are the right usages of static I came up after 25 years of...
Using C#9 record and init property in your .NET Framework 4.x, .NET Standard and .NET Core projects
C#9 record and C#9 init property are really nice addition to the language. As explained in C#9 records: immutable classes, both are syntactic sugar that don’t require any change at...
C# Index and Range Operators Explained
C#8 added the index ^ and range .. operators. In this post I am attempting to demystify both in the most comprehensive way. The index operator ^ Let’s start with...
C#9 records: immutable classes
Record is a long time awaited feature now proposed by C# 9. Finally we have a concise syntax to express this: [crayon-62be9907efa76423301962/] Isn’t it beautiful? In the NDepend code itself...
New C#9 keywords ‘and’ ‘or’ ‘not’
HoweverThe C#9 language introduces new controversial keywords: and keyword: Conjunctive patterns. Require both patterns to match or keyword: Disjunctive patterns. Require either pattern to match not keyword: Negative patterns. Require...