C# MemoryStream先写后读的奇怪现象
生活随笔
收集整理的這篇文章主要介紹了
C# MemoryStream先写后读的奇怪现象
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
C# MemoryStream先寫(xiě)后讀的奇怪現(xiàn)象
static void Main(string[] args){MemoryStream ms = new MemoryStream();BinaryWriter bw = new BinaryWriter(ms);int ix0 = 0x12341314;//注意int ix1 = 2;bw.Write(ix0);bw.Write(ix1);//bw.Flush();//bw.Close();byte[] bes = ms.GetBuffer();Console.WriteLine(bes.Length);//-------------------------------------FLAG-------------------------------------BinaryReader br = new BinaryReader(new MemoryStream(bes));//FLAG1:這樣寫(xiě)可以正確讀取//BinaryReader br = new BinaryReader(ms);//FLAG2:這樣寫(xiě)會(huì)使下面的讀取出現(xiàn)異常//-------------------------------------FLAG-------------------------------------//大小端測(cè)試-CPU寄存器存儲(chǔ)超過(guò)一個(gè)字節(jié)的數(shù)據(jù)的存放順序//若是小端,依次輸出:0x14, 0x13, 0x34, 0x12//若是大端,依次輸出: 0x12, 0x34, 0x13, 0x14int x0 = br.ReadByte();//如果采用FLAG2代碼,這里出現(xiàn)異常:無(wú)法在流的結(jié)尾之外進(jìn)行讀取int x1 = br.ReadByte();int x2 = br.ReadByte();int x3 = br.ReadByte();int x4 = br.ReadByte();}?
posted on 2017-02-08 11:36 時(shí)空觀察者9號(hào) 閱讀(...) 評(píng)論(...) 編輯 收藏
總結(jié)
以上是生活随笔為你收集整理的C# MemoryStream先写后读的奇怪现象的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: LUA表 pairs, ipairs输出
- 下一篇: C#预编译的问题