大多数effecient方式来连接字符串 [英] Most effecient way to concatenate strings

查看:92
本文介绍了大多数effecient方式来连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What's the most efficient way to concatenate strings?

推荐答案

StringBuilder.Append()方法比使用+运算符好得多。但我发现,当串联小于1000,的string.join()甚至比更有效的StringBuilder

The StringBuilder.Append() method is much better than using the + operator. But I've found that, when the concatenations are less than 1000, String.Join() is even more efficient than StringBuilder.

StringBuilder sb = new StringBuilder();
sb.Append(someString);

的string.join 唯一的问题是,你必须有一个共同的分隔符来连接字符串。

The only problem with String.Join is that you have to concatenate the strings with a common delimiter.

string key = String.Join("_", new String[] 
{ "Customers_Contacts", customerID, database, SessionID });

这篇关于大多数effecient方式来连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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