What is the easiest way to get a stream from a string

Is there an accepted idiom or a quick and easy way to get a streaming representation of a string?

Or my best bet is a new MemoryStream(Encoding.Unicode.GetBytes(myStr))where where myStris some string variable?

+3
source share
1 answer

Assuming you want UTF8, then yes, the code shown in the question is absolutely correct.

The only thing I would change: think about whether your API should really talk about TextReader, not Stream. If so, it new StringReader(myStr)will do beautifully.

Stream , , ( using, , , MemoryStream - Dispose(), , p)

+5

All Articles