string or StringBuilder return ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pamelafluente@libero.it

    string or StringBuilder return ?

    A curiosity.

    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.Str ingBuilder

    Function Whatever1() As String
    ....
    Return sb.ToString

    End Function

    Function Whatever2() As System.Text.Str ingBuilder
    ....
    Return sb

    End Function



    ( I guess that for web services string is better (?) )

    -P

  • Phill W.

    #2
    Re: string or StringBuilder return ?

    pamelafluente@l ibero.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 "understand ing" the .Net StringBuilder class. ;-)

    HTH,
    Phill W.


    >
    -P
    >

    Comment

    • pamelafluente@libero.it

      #3
      Re: string or StringBuilder return ?

      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:
      pamelafluente@l ibero.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 "understand ing" the .Net StringBuilder class. ;-)
      >
      HTH,
      Phill W.
      >
      >
      >

      -P

      Comment

      • Brian Cryer

        #4
        Re: string or StringBuilder return ?

        <pamelafluente@ libero.itwrote in message
        news:1158248797 .539586.62120@k 70g2000cwa.goog legroups.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
        Brian Cryer's home page, a collection of notes on my professional and personal interests. Including C#, VB.Net, Windows, DB admin, Delphi and more.



        Comment

        • pamelafluente@libero.it

          #5
          Re: string or StringBuilder return ?

          Thanks. Now I can see it :)

          Brian Cryer ha scritto:
          <pamelafluente@ libero.itwrote in message
          news:1158248797 .539586.62120@k 70g2000cwa.goog legroups.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

          Comment

          Working...