String.Concat vs String.Format [英] String.Concat vs String.Format

查看:202
本文介绍了String.Concat vs String.Format的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用字符串是一种罪过,让我们跳过那部分...


哪一个更快,占用的内存更少?


String.Format(" SomeValue =''{0}''",m_Value);





String .Concat(" SomeValue =''",m_Value,"''");


- ramadu

I know its a sin to use strings, lets skip that part...

Which of these is faster and uses less memory?

String.Format("SomeValue=''{0}''", m_Value);

or

String.Concat("SomeValue=''", m_Value, "''");

- ramadu

推荐答案

如果你对它有所了解,你会得到答案。


String.Concat正是这样做的,它从中获取名称,而

String.Format可以做很多事情,并且必须首先扫描字符串格式

说明符。

" ramadu" < tn*@newsgroups.nospam> schrieb im Newsbeitrag

新闻:%2 ****************** @ TK2MSFTNGP04.phx.gbl ...
If you think a bit about it you ''ll get the answer.

String.Concat is made to do exactly this where it get the name from, whereas
String.Format can do lots of stuff and has to scan the string for format
specifiers first.
"ramadu" <tn*@newsgroups.nospam> schrieb im Newsbeitrag
news:%2******************@TK2MSFTNGP04.phx.gbl...
我知道使用字符串是一种罪过,让我们跳过那部分...

其中哪一种更快,占用的内存更少?

String.Format(&SomeDalue = ''{0}''",m_Value);



String.Concat(" SomeValue =''",m_Value,"''" ;);

- ramadu
I know its a sin to use strings, lets skip that part...

Which of these is faster and uses less memory?

String.Format("SomeValue=''{0}''", m_Value);

or

String.Concat("SomeValue=''", m_Value, "''");

- ramadu



我意识到这一点,但.net做了任何编译器优化,如果
$ b使用$ b string.Format?


- ramadu


I realize that but does .net do any compiler optimizations if
string.Format is used?

- ramadu

:
如果你对它有所了解你会得到答案。

String.Concat正是这样做的,它从中获取名称,而
String.Format可以做很多东西,并且必须扫描首先是格式化的字符串
说明符。

" ramadu" < tn*@newsgroups.nospam> schrieb im Newsbeitrag
新闻:%2 ****************** @ TK2MSFTNGP04.phx.gbl ...
If you think a bit about it you ''ll get the answer.

String.Concat is made to do exactly this where it get the name from, whereas
String.Format can do lots of stuff and has to scan the string for format
specifiers first.
"ramadu" <tn*@newsgroups.nospam> schrieb im Newsbeitrag
news:%2******************@TK2MSFTNGP04.phx.gbl...
我知道它的一个罪恶使用字符串,让我们跳过那部分...

其中哪一个更快,使用更少的内存?

String.Format(&SomeDalue =''{0 }''",m_Value);



String.Concat(" SomeValue =''",m_Value,"''");

- ramadu
I know its a sin to use strings, lets skip that part...

Which of these is faster and uses less memory?

String.Format("SomeValue=''{0}''", m_Value);

or

String.Concat("SomeValue=''", m_Value, "''");

- ramadu




你好ramadu,


如果你使用反射器,你可以看到String.Format使用StringBuilder类

并调用它非常丰富的AppendFormat方法。

String,Contat使用string.FastAllocateString和FillStringChecked方法


我会假设String.Concat是最快的情况


r>我知道使用字符串是一种罪过,让我们跳过那部分...

r>

r>哪一项更快,占用内存更少?

r>

r> String.Format(" SomeValue =''{0}''",m_Value);

r>

r>或者

r>

r> String.Concat(" SomeValue =''",m_Value,"''");

r>

r> - ramadu

r>

---

WBR,

Michael Nemtsev ::博客: http://spaces.msn.com/laflour


有时一个人仍然忠于一个事业,只因为它的对手没有,b $ b不再是平淡无奇的。 (c)Friedrich Nietzsche
Hello ramadu,

If u use reflector you can see that String.Format use StringBuilder class
and calls its AppendFormat method that is pretty rich.
String,Contat uses string.FastAllocateString and FillStringChecked methods

I''d assume that String.Concat is more fastest case

r> I know its a sin to use strings, lets skip that part...
r>
r> Which of these is faster and uses less memory?
r>
r> String.Format("SomeValue=''{0}''", m_Value);
r>
r> or
r>
r> String.Concat("SomeValue=''", m_Value, "''");
r>
r> - ramadu
r>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


这篇关于String.Concat vs String.Format的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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