Solved

Equivalent to StringBuilder for bytes?

Posted on 2007-04-03
3
2,040 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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