Solved

Equivalent to StringBuilder for bytes?

Posted on 2007-04-03
3
2,035 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
ID: 18842889
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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18842905
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
ID: 18845006
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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