Performance issues that need to be considered when programming in C#
Nowadays, C# is one of the most used programming languages in the world, so awareness of C# programming best practices is fundamental for the design of good architectures that satisfy the most common non-functional requirements.
The following sections mention a few simple but effective tips – the associated code samples are available in this book’s GitHub repository. It is worth mentioning that .NET Foundation has developed a library dedicated to benchmarking called BenchmarkDotNet. You may find it useful for your scenarios. Check it out at https://benchmarkdotnet.org/.
String concatenation
This is a classic one! A naive concatenation of strings with the +
string operator may cause serious performance issues since every time two strings are concatenated; their contents are copied into a new string.
So, if we concatenate, for instance, 10 strings that have an average length of 100, the...