using System; using System.IO; class Program { static void Main(string[] args) { byte[] data = { 1, 2, 3, 4, 5 }; MemoryStream stream = new MemoryStream(data); int byteRead; while ((byteRead = stream.ReadByte()) != -1) { Console.WriteLine(byteRead); } } }
1 2 3 4 5
using System; using System.IO; class Program { static void Main(string[] args) { byte[] data = { 1, 2, 3, 4, 5 }; MemoryStream stream = new MemoryStream(data); Console.WriteLine(stream.ReadByte()); // outputs 1 Console.WriteLine(stream.ReadByte()); // outputs 2 Console.WriteLine(stream.ReadByte()); // outputs 3 } }
1 2 3These examples use the System.IO namespace, which is a standard library in C#.