teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コードを変更

2017/04/11 02:02

投稿

KSwordOfHaste
KSwordOfHaste

スコア18404

answer CHANGED
@@ -10,11 +10,13 @@
10
10
  public static class MyCSharpExtension {
11
11
  // extension method の定義例
12
12
  public static IEnumerable<byte> ReadBytes(this FileStream fs) {
13
+ byte[] buffer = new byte[4096];
13
14
  for (;;) {
14
- int b = fs.ReadByte();
15
+ int len = fs.Read(buffer, 0, buffer.Length);
15
- if (b < 0) break;
16
+ if (len == 0)
17
+ break;
18
+ for (int i = 0; i < len; i++)
16
- yield return (byte)b;
19
+ yield return buffer[i];
17
- }
18
20
  }
19
21
  }
20
22
  }