Is there an accepted idiom or a quick and simple way to get a stream representation of a string?
Or is my best bet a new MemoryStream(Encoding.Unicode.GetBytes(myStr)) where myStr is some string variable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you want UTF8, then yes the code shown in the question is entirely correct.
The only thing I would change is: consider whether your API should actually be talking about
TextReaderrather thanStream. If so,new StringReader(myStr)would do nicely.But for arbitrary binary
Streamusage, your code is correct as shown (especially if you add ausing, although in reality that is moot since forMemoryStreamit is a no-opDispose(); but I’m fussy ;p)