System.ValueType and string builder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Johansson

    System.ValueType and string builder

    Hello!

    Everything not derived from System.ValueTyp e is a reference type.

    I just wonder this ValueType type is derived from Object and it
    overrides the two methods Equals and GetHashCode which is derived from
    Object.
    What is the reson for overriding these two methods ?

    One mode question.
    What does it mean when it says "The StringBuilder solution is the most
    flexible because it can span multiple
    statements."So what does it mean with this span multiple statements?

    //Tony


  • Peter Duniho

    #2
    Re: System.ValueTyp e and string builder

    On Sun, 21 Sep 2008 11:25:51 -0700, Tony Johansson
    <johansson.ande rsson@telia.com wrote:
    Hello!
    >
    Everything not derived from System.ValueTyp e is a reference type.
    >
    I just wonder this ValueType type is derived from Object and it
    overrides the two methods Equals and GetHashCode which is derived from
    Object.
    What is the reson for overriding these two methods ?
    So that it can provide value-type semantics for them. Specifically, by
    comparing the actual data contained in the instance, rather than just the
    references. Not only is this more useful, it's absolutely necessary since
    there's no reliable "instance" reference when dealing with value types.
    One mode question.
    What does it mean when it says "The StringBuilder solution is the most
    flexible because it can span multiple
    statements."So what does it mean with this span multiple statements?
    When what says? You forgot to include a link to whatever you're looking
    at.

    As far as the statement goes, I don't really understand it. I mean, yes
    you can call StringBuilder repeatedly, appending more and more strings to
    it. But you can do that with string concatenation too. It's much more
    efficient to append strings over the course of multiple statements with
    StringBuilder that with string concatenation, but it's not like the latter
    is impossible.

    Maybe if you'd provide the context for the statement, there's some
    alternative interpretation that makes more sense.

    Pete

    Comment

    Working...