什么是使用Path.Combine在串联与'+'字符串的优势在哪里? [英] What is the advantage of using Path.Combine over concatenating strings with '+'?

查看:540
本文介绍了什么是使用Path.Combine在串联与'+'字符串的优势在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太看到其中的差别。

I don't quite see the difference.

有什么能 Path.Combine 做的比完美的工作字符串连接好?

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 使用 Path.PathSeparator 和它检查第一路径是否具有已在最后的分离器,所以它不会重复隔板。此外,它会检查路径元素是否有合并字符无效

Path.Combine uses the Path.PathSeparator and it checks whether the first path has already 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在串联与'+'字符串的优势在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆