Is there a performance difference between String.Replace(char, char) and String.Replace(string, string) when I just need to replace once character with another?
Is there a performance difference between String.Replace(char, char) and String.Replace(string, string) when I just
Share
Yes, there is: I ran a quick experiment, and it looks like the string version is about 3 times slower.
1.466s vs 4.583s
This is not surprising, because the overload with strings needs an extra loop to go through all characters of the
oldString. This loop runs exactly one time, but the overhead is still there.