Solved

Equivalent to StringBuilder for bytes?

Posted on 2007-04-03
3
2,016 Views
Last Modified: 2013-11-07
Is there an equivalent to the StringBuilder class for writing values which are automatically converted to a byte array and then added to an internal byte array?
Example:

ByteBuilder bb = new ByteBuilder();
bb.Write(1.0f);
bb.Write(false);
bb.Write(3.1);
return bb.AllBytes();

Note: This class ByteBuilder, I'm searching for an equivalent IN the .net Framework.
0
Comment
Question by:makronium
3 Comments
 
LVL 11

Expert Comment

by:Babycorn-Starfish
Comment Utility
Hi,

you could certainly make one but i've never seen something like you've outlined in the .NET framework - hopefully one exists though and its just obscure.

Best of luck
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
nothing built-in.

found this project that has a class coded:
http://www.codeproject.com/csharp/lobby.asp?df=100&forumid=302662&exp=0&select=1681995
0
 
LVL 37

Expert Comment

by:gregoryyoung
Comment Utility
might have accepted too quickly .. would a MemoryStream and a BinaryWriter not do just this? :)

http://msdn2.microsoft.com/en-us/library/system.io.binarywriter.aspx

MemoryStream m = new MemoryStream();
BinaryWriter writer = new BinaryWriter(m);
writer.write(true);
writer.write("hello");
writer.write(12345);
writer.Flush();
return m.ToArray();
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now