Created
July 10, 2017 22:24
-
-
Save gustavodaquino/c94c4ffaea69a36a905a7147ed9b921f to your computer and use it in GitHub Desktop.
C# program that uses the MemoryStream type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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