连接字符串的最有效方法是什么?
最佳答案
Rico Mariani ,.NET 性能大师,拥有 an article在这个问题上。这并不像人们想象的那么简单。基本建议是这样的:
If your pattern looks like:
x = f1(...) + f2(...) + f3(...) + f4(...)
that's one concat and it's zippy, StringBuilder probably won't help.
If your pattern looks like:
if (...) x += f1(...)
if (...) x += f2(...)
if (...) x += f3(...)
if (...) x += f4(...)
then you probably want StringBuilder.
Yet another article to support this claim来自 Eric Lippert,他详细描述了对单行 +
连接执行的优化。
关于c# - 连接字符串的最有效方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21078/