作者heyshi (ishyeh)
看板C_Sharp
標題[問題] fread & BinaryReader
時間Thu Jul 31 15:18:42 2008
請問大家我這有個 C code 的fread function
short data[240];
FILE *ifileid;
fread(data,sizeof(short),240,ifileid);
檔案是 bin 檔
所以打算用 在c# binaryreader 來做
在 底下是有找到 ReadInt16() 來讀 short
不過這只能一次讀一個short
請問該如何像fread 可以選擇我要搬多少 short ?
謝謝
public static short[] ReadInt16Array(BinaryReader reader, int count)
{
short[] result = new short[count];
for(int i=0;i<count,i++)
{
result[i] = reader.ReadInt16();
}
return result;
}
目前只找到這方法 請問有更好的嗎
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.26.228.10
※ 編輯: heyshi 來自: 163.26.228.10 (07/31 16:39)
1F:推 toki:System.IO.FileStream.Read() 07/31 17:10
2F:推 proach:可以直接Read( data, offset, length)啊 08/01 16:55