Always revisit and benchmark your custom code workarounds with each version of .NET. The .NET framework and the JIT compiler gets faster 🚀 all the time so the built-in methods may eventually outperform custom ‘clever’ ones you have written.
The image below is a screenshot from Microsofts Stephen Toub’s ‘Performance Improvements in .NET 7‘ presentation at .NET Conf in November 2022.
It shows a nice example of how custom code which checks if a string starts with another particular string performs better than the built in String.StartWith method in .NET Framework 4.8 and .NET 6 but then performs slower than the built in method in .NET 7.
Click on the image for a larger view in a new window …
‘Work-arounds Should Be Revisited‘ section of Stephens presentation ->
(506) Performance Improvements in .NET 7 | .NET Conf 2022 – YouTube
Stephens full presentation below…