Quick way to get the contents of a MemoryStream as an ASCII string

前端 未结 2 1974
迷失自我
迷失自我 2021-02-13 23:15

I have a JSON string in a MemoryStream. I am using the following code to get it out as an ASCII string:

MemoryStream memstream = new MemoryStream(); 
/* Write a          


        
2条回答
  •  清酒与你
    2021-02-14 00:00

    You could use the ToArray method:

    using (var stream = new MemoryStream())
    {
        /* Write a JSON string to stream here */
    
        string jsonString = Encoding.ASCII.GetString(stream.ToArray());
    }
    

提交回复
热议问题