Steve Fenton

c#

You can subscribe to the c# tag micro-feed.

Counting a Non-Generic IEnumerable

You rarely come across them in 2021, but there is such a thing as a non-generic IEnumerable. They exist in System.Collections rather than System.Collections.Generic. Since .NET 2 pretty much everyone is full-on using generics as they are the best thing since curly-braces… but occasionally you find one and even more rarely you need to count […]

Strings Contain Empty Strings

This is just one of those philosophical moments in programming where one small details can have a big impact. In C# / .NET you will find that when you ask if a string contains an empty string (string.Empty), the answer is yes. This may seem logically surprising so it is worth bearing in mind should […]

The type or namespace name ‘ApplicationInsights’ does not exist in the namespace ‘Microsoft’

If you uninstall the Application Insights package from a .NET Core MVC project, you might get a few errors as it can’t “remove all the references” that might have made it into your application. The changes to StartUp.cs will be pretty self-explantory, but elsewhere you will get something a bit more off-the-wall as it references […]

C# 9 Covariant Return Types

Just a quick note on a neat feature in C# 9 that will allow sub-classes to return a covariant return type… what?! Okay, it allows you to return a more specific, or narrower type. For example, we used to have to return the same type… // parent class… public virtual Literature GetLiterature(…) { return new […]

C# 9 Non-Null Parameters

This neat C# 9 feature can be summed up in a tiny snippet of code. You know that code analysis warning that tells you that the argument passed might be null… wouldn’t it be nice if you could refuse to accept null? Well, you can. This is the before… public Book(string firstName, string lastName) And […]

C# 9 Record Types

Update! Since this article was published, it is almost certain that the keyword for record types will actually be record not data as it was in this early preview. We have taken a quick look at C# 9 Initializers and Immutability and C# 9 Non-Destructive Mutation. Let’s now look at the full transformation from an […]

C# 9 Non-Destructive Mutation

There are some phrases in programming that feel like they belong in a superhero movie. Non-destructive mutation is just such as phrase. It refers to a concept in functional programming that means when you want to change the state of an object, you create a copy with the change – rather than changing the original. […]