String Builder&字符串,有什么区别? [英] String Builder & String, what's the difference ?

查看:62
本文介绍了String Builder&字符串,有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String Builder&字符串,有什么区别。

以及何时使用哪个?

谢谢。

解决方案

周五,2004年6月25日10:24:00 +0800,Tee< th*@streamyx.com>写道:

String Builder&字符串,有什么区别。
以及何时使用?

谢谢。




基本上字符串适用于永不改变的值;但是如果你创建了一个

''字符串式'变量并且需要更改它的值(比如

将字符串值连接在一起),请使用StringBuilder:

http: //msdn.microsoft.com/library/en...ilderclass.asp

-

Craig Deelsnyder

Microsoft MVP - ASP / ASP.NET


字符串是不可变的。这意味着如果你尝试:string1 = string1 + string2,

它需要为string1创建一个新的内存位置并为GC设置原始的

位置。


StringBuilder的行为不是这样的。


Don


" Tee" < th*@streamyx.com>在消息中写道

news:#U ************** @ tk2msftngp13.phx.gbl ...

String Builder&字符串,有什么区别。
以及何时使用?

谢谢。



< blockquote> Tee,


这是我对它的看法:


每当你需要进行大量的字符串操作时,请使用stringbuilder。对于

快速/小事,我不打扰。所以,如果我只是在一个

行中添加一个字符串,我会做这样的事情 -


strA = strB& strC


然而,我有一个循环,我在做1,200个连接。使用

字符串构建器减少了大量占用的时间。


其他人可能感觉不一样,但这对我有用。


-Saul

Tee < th*@streamyx.com>在消息中写道

news:%2 **************** @ tk2msftngp13.phx.gbl ...

String Builder &安培;字符串,有什么区别。
以及何时使用?

谢谢。



String Builder & String, what''s the difference.
and when to use which ?
Thanks.

解决方案

On Fri, 25 Jun 2004 10:24:00 +0800, Tee <th*@streamyx.com> wrote:

String Builder & String, what''s the difference.
and when to use which ?
Thanks.



Basically String is fine for never-changing values; but if you create a
''string-like'' variable and need to change it''s value (such as
concatenating a string value together) use StringBuilder:

http://msdn.microsoft.com/library/en...ilderclass.asp
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Strings are immutable. Meaning if you try to: string1 = string1 + string2,
it needs to create a new memory location for string1 and set the original
location for GC.

StringBuilder does not behave this way.

Don

"Tee" <th*@streamyx.com> wrote in message
news:#U**************@tk2msftngp13.phx.gbl...

String Builder & String, what''s the difference.
and when to use which ?
Thanks.



Tee,

Here''s my take on it :

Use stringbuilder whenever you need to do LOTS of string manipulations. For
quick/little things, I don''t bother. So if I''m just adding a string in one
line I would do something like this --

strA = strB & strC

However, I had a loop where I was doing about 1,200 concatinations. Using
string builder reduced the time this took substantially.

Others may feel different, but this works for me.

-Saul
"Tee" <th*@streamyx.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

String Builder & String, what''s the difference.
and when to use which ?
Thanks.



这篇关于String Builder&amp;字符串,有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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