Why does MemoryStream.GetBuffer() always throw?

后端 未结 4 1580
滥情空心
滥情空心 2021-01-03 22:21

The following code will always throw UnuthorizedAccessException (MemoryStream\'s internal buffer cannot be accessed.)

byte[] buf1 = { 2, 3, 5, 7, 11 };
var         


        
4条回答
  •  被撕碎了的回忆
    2021-01-03 22:37

    To add to what others have already put in here...

    Another way to get your code to work is change your code to the following line.

    byte[] buf2 = ms.ToArray();
    

提交回复
热议问题