Skip to content

Instantly share code, notes, and snippets.

@gustavodaquino
Created July 10, 2017 22:24
Show Gist options
  • Save gustavodaquino/c94c4ffaea69a36a905a7147ed9b921f to your computer and use it in GitHub Desktop.
Save gustavodaquino/c94c4ffaea69a36a905a7147ed9b921f to your computer and use it in GitHub Desktop.
C# program that uses the MemoryStream type
using System;
using System.IO;
class Program
{
static void Main()
{
// Read all bytes in from a file on the disk.
byte[] file = File.ReadAllBytes("C:\\ICON1.png");
// Create a memory stream from those bytes.
using (MemoryStream memory = new MemoryStream(file))
{
// Use the memory stream in a binary reader.
using (BinaryReader reader = new BinaryReader(memory))
{
// Read in each byte from memory.
for (int i = 0; i < file.Length; i++)
{
byte result = reader.ReadByte();
Console.WriteLine(result);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment