- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert byte array to an object stream in C#?
Stream is the abstract base class of all streams and it Provides a generic view of a sequence of bytes. The Streams Object involve three fundamental operations such as Reading, Writing and Seeking. A stream be can be reset which leads to performance improvements.
A byte array can be converted to a memory stream using MemoryStream Class.
MemoryStream stream = new MemoryStream(byteArray);
Example
Let us consider a byte array with 5 values 1, 2, 3, 4, 5.
using System; using System.IO; namespace DemoApplication { class Program { static void Main(string[] args) { byte[] byteArray = new byte[5] {1, 2, 3, 4, 5 }; using (MemoryStream stream = new MemoryStream(byteArray)) { using (BinaryReader reader = new BinaryReader(stream)) { for (int i = 0; i < byteArray.Length; i++) { byte result = reader.ReadByte(); Console.WriteLine(result); } } } Console.ReadLine(); } } }
Output
The output of the above code is
1 2 3 4 5
- Related Articles
- How to convert an input stream to byte array in java?
- How to convert an object to byte array in java?
- How to convert byte array to string in C#?
- How to Convert a Java 8 Stream to an Array?
- Program to convert Stream to an Array in Java
- Convert byte primitive type to Byte object in Java
- How to convert BLOB to Byte Array in java?
- How to convert Byte Array to Image in java?
- How to convert Image to Byte Array in java?
- How to convert InputStream to byte array in Java?
- How to convert an object array to an integer array in Java?
- How to convert a PDF to byte array in Java?
- How to convert java bitmap to byte array In android?
- How to convert hex string to byte Array in Java?
- How to convert an object into an array in JavaScript?

Advertisements