不鸣则已

海阔凭鱼跃,天高任鸟飞!

首页 新随笔 联系 订阅 管理

GetBuffer():

Note that the buffer contains allocated bytes which might be unused. For example, if the string "test" is written into the MemoryStream object, the length of the buffer returned from GetBuffer is 256, not 4, with 252 bytes unused. To obtain only the data in the buffer, use the ToArray method; however, ToArray creates a copy of the data in memory.

The buffer can also be null.

This method works when the memory stream is closed.

微软官方的解释:请注意,缓冲区包含这可能是未分配的字节。例如,如果将字符串“测试”被写入MemoryStream对象,该缓冲区的长度从的GetBuffer返回的是256,而不是4,具有252个字节未使用。为了获得只在缓冲区中的数据使用ToArray方法;然而,ToArray在内存中创建了数据的副本。

 

ToArray() :

This method omits unused bytes in MemoryStream from the array. To get the entire buffer, use the GetBuffer method.

This method returns a copy of the contents of the MemoryStream as a byte array.

微软官方的解释:此方法返回内存流内容副本作为一个字节数组。(真实数据)

posted on 2014-07-22 13:59  唐群  阅读(1036)  评论(0编辑  收藏  举报