Replace and remove whitespaces in strings - performant and sustainable
There are many ways to remove spaces or other characters in a string - there are just very big differences in terms of performance and efficiency.
Read Blog PostThere are many ways to remove spaces or other characters in a string - there are just very big differences in terms of performance and efficiency.
Read Blog PostCode formatting is a very important element when developers work together on a project - and you are always well advised not to invent your own formatting rules, but to use those that are a standard or de facto standard in the respective programming language.
In C#, many rules are now controlled via the editorconfig
, but there is still a lack of standardized formatting tools in .NET - dotnet format simply does not support many things - so that different functionalities exist in different IDEs (Visual Studio
, Visual Studio Code, Rider).
Sustainable Code is a constantly growing GitHub repository created by me
, in which I collect various everyday code snippets and measure the performance of the different implementation ways.
The goal is to create a collection of code that virtually everyone has in front of them every day and can thus easily implement the best way for themselves and their use case.
A popular unit test - and also a necessary test - is the correct registration of interfaces and their implementation with dependency injection. And a common mistake is that the associated IServiceCollection interface is used for mocks that lead to faulty tests.
Read Blog PostWhen working with ZIP files in .NET, there may be cases where the file is not stored on disk but comes directly as a Stream. This could happen if you’re downloading the ZIP file from a network, receiving it via an API, or working with in-memory file data. In this blog post, I’ll show you a simple example of handling ZIP files using streams in .NET and how to process their content without saving the ZIP to disk.
Read Blog PostWorking with compressed files is common in many applications, whether you’re extracting data from an archive, installing software packages, or retrieving bundled files. Thankfully, .NET finally provides an efficient, straightforward way to decompress ZIP files using the System.IO.Compression namespace. In this post, I’ll walk through a simple code snippet that you can use to decompress ZIP files in your .NET apps.
Read Blog PostWhen working with .NET apps you may sometimes need to bundle multiple files into a single compressed archive for easier storage, transfer, or processing. In this post, I’ll show you a simple and effective way to compress a folder into a .zip file using just a few lines of code with the built-in .NET namespace System.IO.Compression .
Read Blog PostIn C# (.NET 6 and above), there is now a very simple way to read out the CPU load with minimal overhead - i.e. without threads. The PerformanceCounter from the System.Diagnostics namespace helps us with this.
Dealing with empty lists is an everyday situation in .NET. An empty list is often preferred to a null in order to control the logic. But how expensive is it to return an empty list?
We are currently in the preview phase of .NET 9 , which releases in Nov 2024 - and if you want to test it extensively like I do, store the preview version in the global configuration global.json . But how do you have to define the version here for it to work?
Read Blog Post