String or StringBuilder return values?

前端 未结 3 2070
死守一世寂寞
死守一世寂寞 2021-02-12 18:44

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()?

3条回答
  •  北海茫月
    2021-02-12 19:32

    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

提交回复
热议问题