I don't quite see the difference.
What could Path.Combine do better than perfectly working string concatenation?
I guess it's doing something very similar in the background.
Can anyone tell me why it is so often preferred?
Path. Combine uses the Path. PathSeparator and it checks whether the first path already has a separator at the end so it will not duplicate the separators. Additionally, it checks whether the path elements to combine have invalid chars.
The most efficient is to use StringBuilder, like so: StringBuilder sb = new StringBuilder(); sb. Append("string1"); sb.
Path.Combine uses the Path.PathSeparator and it checks whether the first path already has a separator at the end so it will not duplicate the separators. Additionally, it checks whether the path elements to combine have invalid chars.
Path.Combine does more things than just a string concatenation. If you look at the source code;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With