Steve Fenton

c#

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

C# namespace declarations

Unlike my recent article on Global Using Statement and Code Clues, the new namespace declarations have no trade offs and you should just auto-fix them in your whole project and move on with your life. Here’s how we do namespace before namespace declarations: namespace Fenton.Sample.UI { public class Example { } } …and here is […]

Stripping times from dates in C#

This is a surprisingly common problem in C#, where you need to take a DateTime and strip off the “time” bit to leave you with a representation of a day. Currently, you can do it by creating a new DateTime and passing only the parts you want to keep, like year, month, and day. DateTime […]

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 […]