c# - 连接字符串的最有效方法?

标签 c# .net string performance optimization

连接字符串的最有效方法是什么?

最佳答案

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/

相关文章:

c# - 基于动态资源的样式

c# - 从 Microsoft Visual Web Developer 2008 连接到 MySQL

c# - 检测默认网络浏览器的代理设置

C# 字符串 4096 限制?

c - 递归函数中的逻辑错误

c# - 如何在 TreeView 中显示目录?

c# - PATH 变量的 GetEnvironmentVariable() 和 SetEnvironmentVariable()

c# - 我应该在以下情况下使用锁吗

c# - 有什么方法可以使用 .NET 应用程序来处理 git 吗?

javascript - JS : deserializing a string with a JSON-like structure