Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Performance / July 2004

Tip: Looking for answers? Try searching our database.

String Concatenation in VB.NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
YGeek - 29 Jun 2004 23:06 GMT
Is there a performance issue with using & to do string concatenation versus using the String.Concat method?  What is the best practice for doing string concatenation in VB.NET?
AlexS - 29 Jun 2004 23:29 GMT
Hi, YGeek

Both are same in terms of memory and processor use. And both are
sub-efficient. It is not recommended to use concatenation in loops and
frequently.
The fastest and most efficient way to combine strings is with StringBuilder.

HTH
Alex

> Is there a performance issue with using & to do string concatenation versus using the String.Concat method?  What is the best practice for doing
string concatenation in VB.NET?
Michael Pearson - 30 Jun 2004 00:04 GMT
I second what Alex Says.
If I've got to concatinate two small strings, I usually just use &.
If I'm building a large string in a loop, System.Text.StringBuilder (I think
that's the right namespace) is the way to go by FAR.

Michael
> Hi, YGeek
>
[quoted text clipped - 9 lines]
> versus using the String.Concat method?  What is the best practice for doing
> string concatenation in VB.NET?
Henning Krause - 30 Jun 2004 07:21 GMT
Hello,

if you just concat two strings, you can safely use &.
If you concat more than two strings it is more performant to use
string.Concat.

In a loop, use the StringBuilder.

Greetings,
Henning Krause
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/?page=products)

> I second what Alex Says.
> If I've got to concatinate two small strings, I usually just use &.
[quoted text clipped - 17 lines]
> doing
> > string concatenation in VB.NET?
Jon Skeet [C# MVP] - 30 Jun 2004 08:21 GMT
> if you just concat two strings, you can safely use &.
> If you concat more than two strings it is more performant to use
> string.Concat.

I believe & just uses Concat under the hood anyway, doesn't it?

Note that string literals will be concatenated by the compiler anyway,
so "x" & "y" is exactly the same as "xy".

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Sriram Krishnan - 17 Jul 2004 15:28 GMT
See Rico Mariani's post on the subject
http://weblogs.asp.net/ricom/posts/40778.aspx

Signature

Sriram Krishnan
Microsoft Student Ambassador
http://www.dotnetjunkies.com/weblog/sriram

> > if you just concat two strings, you can safely use &.
> > If you concat more than two strings it is more performant to use
[quoted text clipped - 4 lines]
> Note that string literals will be concatenated by the compiler anyway,
> so "x" & "y" is exactly the same as "xy".
Jon Skeet [C# MVP] - 17 Jul 2004 18:35 GMT
> See Rico Mariani's post on the subject
> http://weblogs.asp.net/ricom/posts/40778.aspx

That post only talks about adding to an existing string. It doesn't say
anything about the case of

string x = y + z;

(or x = y & z in VB.NET) which is what I was talking about in my post.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.