Should I close a StringReader?

前端 未结 5 602
小蘑菇
小蘑菇 2020-12-06 09:40

I use a StringReader to turn a string into something I can upload to an SFTP server (it takes a stream). Is there any point in closing that StringReader

5条回答
  •  不知归路
    2020-12-06 10:32

    If you know you're dealing with a StringReader that you'll be throwing away, I don't see any reason to close it. I can't imagine any reason you'd be holding a reference to it after you'd close it, so there's no real benefit to the string being set to null for garbage collection. If you were creating a method that takes a Reader then it might make sense to close it since you don't know the underlying type.

提交回复
热议问题