What is the advantage of using Path.Combine over concatenating strings with '+'?

后端 未结 5 468
情深已故
情深已故 2020-11-30 10:53

I don\'t quite see the difference.

What could Path.Combine do better than perfectly working string concatenation?

I guess it\'s doing something

5条回答
  •  独厮守ぢ
    2020-11-30 11:22

    Path.Combine does more things than just a string concatenation. If you look at the source code;

    • Checks both paths has invalid character or not
    • Checks second parameter is root path or not
    • Checks last character of first path is director or alt directory or volume separator or not. If not, concatenate both string with directory separator between then

提交回复
热议问题