|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
string or StringBuilder return ?When one can choose the Return (from a function) either StringBuilder (that will be eventually converted to string) or a String, which one would be better to return, in terms of efficiency and good practices. Or it's just the same thing ? Dim sb As New System.Text.StringBuilder Function Whatever1() As String .... Return sb.ToString End Function Function Whatever2() As System.Text.StringBuilder .... Return sb End Function ( I guess that for web services string is better (?) ) -P pamelaflue***@libero.it wrote:
> When one can choose the Return (from a function) either StringBuilder Depends on what you expect the /caller/ of the function to do with it.> (that will be eventually converted to string) or a String, which one > would be better to return, in terms of efficiency and good practices. If they are going to continue bolting more bits of strings together, then send them the the tool to do so, i.e. the StringBuilder. If all they want is the "end result" of your string building, then just send back the "finished" string. > ( I guess that for web services string is better (?) ) Definitely!The whole point of web services is that they can be called from just about /anywhere/. It could be another .Net thing or some Unix application, or some wierd Soap-compliant program that somebody turned out on their dusty, old Commodore - only one of those stands any chance of "understanding" the .Net StringBuilder class. ;-) HTH, Phill W. Show quoteHide quote > > -P > Thanks Phill ;)
Actually, what I was wondering is that if putting a long string in the return stack is more cumbersome than putting there a stringbuilder, which is reference type ... or perhaps they have a mechanism so that strings are anyway passed as a kind of reference ?? -P Phill W. ha scritto: Show quoteHide quote > pamelaflue***@libero.it wrote: > > > When one can choose the Return (from a function) either StringBuilder > > (that will be eventually converted to string) or a String, which one > > would be better to return, in terms of efficiency and good practices. > > Depends on what you expect the /caller/ of the function to do with it. > If they are going to continue bolting more bits of strings together, > then send them the the tool to do so, i.e. the StringBuilder. > > If all they want is the "end result" of your string building, then just > send back the "finished" string. > > > ( I guess that for web services string is better (?) ) > > Definitely! > The whole point of web services is that they can be called from just > about /anywhere/. It could be another .Net thing or some Unix > application, or some wierd Soap-compliant program that somebody turned > out on their dusty, old Commodore - only one of those stands any chance > of "understanding" the .Net StringBuilder class. ;-) > > HTH, > Phill W. > > > > > > > -P > > <pamelaflue***@libero.it> wrote in message
news:1158248797.539586.62120@k70g2000cwa.googlegroups.com... Strings are objects, so whether you use stringbuilder or a string you are > Thanks Phill ;) > > Actually, what I was wondering is that if putting a long string in the > return stack is more cumbersome than putting there a stringbuilder, > which is reference type ... or perhaps they have a mechanism so that > strings are anyway passed as a kind of reference ?? just passing around a reference. So, performance wise, it doesn't matter which you pass around (although there may be benefits one way or the other depending on what you then do with it). Thanks. Now I can see it :)
Brian Cryer ha scritto: Show quoteHide quote > <pamelaflue***@libero.it> wrote in message > news:1158248797.539586.62120@k70g2000cwa.googlegroups.com... > > Thanks Phill ;) > > > > Actually, what I was wondering is that if putting a long string in the > > return stack is more cumbersome than putting there a stringbuilder, > > which is reference type ... or perhaps they have a mechanism so that > > strings are anyway passed as a kind of reference ?? > > Strings are objects, so whether you use stringbuilder or a string you are > just passing around a reference. So, performance wise, it doesn't matter > which you pass around (although there may be benefits one way or the other > depending on what you then do with it). > -- > Brian Cryer > www.cryer.co.uk/brian
That Eval Question Again...
Simple Eval() (Ithink) question Optional Paramter Question NullReferenceException on DataGridView.Columns Index property Can we Read the text contents from PDF using .net Threading using QueueUserWorkItem VB to Delphi Help! Change OpenFileDialog Size (width and height) how to devide string to array? Filling a DataGrid with a DataSet |
|||||||||||||||||||||||