字符串连接和复杂性? [英] Strings joining and complexity?

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

问题描述

当我需要连接两个字符串时,我使用String.Format(或StringBuilder,如果它发生在代码中的多个位置)。

When I need to join two strings I use String.Format (or StringBuilder if it happens in several places in the code).

我看到一些优秀的程序员

I see that some good programmers doesn't give attention to strings joining complexity and just use the '+' operator.

我知道使用'+'运算符会使应用程序使用更多的内存,但是复杂度如何?

I know that using the '+' operator make the application to use more memory, but what about complexity?

推荐答案

这是一篇很棒的文章,关于我们自己的 Jeff Atwood 编码恐怖

This is an excellent article about the different string join methods by our own Jeff Atwood on Coding Horror:



(来源: codinghorror.com

微观优化剧院的悲剧

这是帖子的要旨。


[ 显示了几个字符串连接方法]

将发痒的小触发手指
移出编译键,然后考虑一下
一分钟。这些
方法中哪一种会更快?

Take your itchy little trigger finger off that compile key and think about this for a minute. Which one of these methods will be faster?

得到答案了吗?

然后请.. drumroll ..正确的
答案:

它。只是。不。

And.. drumroll please.. the correct answer:

It. Just. Doesn't. Matter!

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

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