String or StringBuilder return values?

前端 未结 5 1786
生来不讨喜
生来不讨喜 2021-02-12 19:06

If I am building a string using a StringBuilder object in a method, would it make sense to:

Return the StringBuilder object, and let the calling code call ToString()?

5条回答
  •  渐次进展
    2021-02-12 19:22

    I would say the method should return sb.ToString(). If the logic surrounding the creation of the StringBuilder() object should change in the future it makes sense to me that it be changed in the method not in each scenario which calls the method and then goes on to do something else

提交回复
热议问题