473,805 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing Byte Array to Disk

I've got code that allows me to render the contents of a
byte array to the screen, but I need to write the contents
to disk. Suggestions?

Thanks
Oct 1 '07
11 4525
I would agree that if you have the explicit type declaration on the
right side, then I would say var is ok on the left side. However, in the
case of a return value from a function, you are forcing a lookup for anyone
that has to maintain the code who might not know what the return value is.

As for book listings, I would say that it can be handy, but if used
improperly, or too gingerly, you aren't going to convey your points very
well. But I haven't written a book, so I can't say.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c omwrote:
> In this case, I don't like it. It adds ambiguity to the code, in the
sense that you don't know what type you are working with (you have to
know
the return type of the Open method on the File class, which is
unreasonable ). For projections on anonymous types in queries for LINQ,
it
definitely makes sense, but in cases where you know the type, I think it
is
a bad practice.

In this particular case, I *might* agree - because it's not clear what
File.Open returns, although it's *fairly* obvious.

When you're using an object creation expression as the right hand side,
I like it a lot, particularly when the names get long:

var namesToPeople = new Map<string,Pers on>();

is clearer to me than

Map<string,Pers onnamesToPeople = new Map<string,Pers on>();

There's no ambiguity at all - you can tell that namesToPeople is
definitely going to be of type Map<string,Pers on- but there's also no
redundancy, and less fluff to get in the way.

(It's particularly handy in listings for books, where horizontal space
is at a premium, but that's slightly different :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Oct 2 '07 #11
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c omwrote:
> I would agree that if you have the explicit type declaration on the
right side, then I would say var is ok on the left side. However, in the
case of a return value from a function, you are forcing a lookup for
anyone
that has to maintain the code who might not know what the return value
is.

Yes. I think it depends on what the method is though - File.Open is a
pretty common one, for instance. Various other methods are very obvious
in terms of what they return - Guid.NewGuid, for instance, although in
that case you'd only be saving a single character anyway.
> As for book listings, I would say that it can be handy, but if used
improperly, or too gingerly, you aren't going to convey your points very
well. But I haven't written a book, so I can't say.

Oh it's certainly got to be used with care, yes. And only after
explaining what it does :)

Oh god, don't tell me C# is becoming VB? <just kidding>

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

Oct 3 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
9118
by: Ali | last post by:
Hi I want to write (or read) to a stream, but the data is not byte array I converted the data to byte array manually, but it is very slow, (becuse the data is very large) Is another way for this kind of writing and reading best regard Ali.
1
15961
by: Greg Patrick | last post by:
My problem: I load an some assemblies (strong named) from a byte array using Assembly.Load(byte). They load fine. But one one of them is actually accessed, it's referenced assemblies can't be found on disk and I get a TargetInvocationExeption. For example, let's say I have a C# win forms application called Prog. Prog.exe uses Assembly.Load(byte) to load two C# class library assemblies,
1
4093
by: dsmith | last post by:
I need to write a data array out to disk, but unfortunately am running into performance issues. The function is essentially: private ushort theInt16Array = new ushort; public void Save(BinaryWriter bw) { /// Far too slow: // for (int row = 0; row < Rows; row++) // {
2
6863
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to replace just one item. I know I can get the entire array, then save the whole thing (with a for loop and if statements so that the changed data will be saved), but it seems like a lot of unnecessary reading and writing. Is there a way to directly save...
3
1551
by: Fireangel | last post by:
I want to cast a class into a byte array. I've seen some examples of this floating around, but they all have simple data members. What happens if I cast something that has a ArrayList or an Array?? Does it loop through the array and cast them all and I end up with a big array (This is what I hope will happen)? Or does it simple cast the pointer address and I end up with a small array?? Related question: How do I make sure everything...
2
3413
by: Lars Netzel | last post by:
Here's what I need to do: Due to a bug in Crystal Reports ExportToStream() method I can't stream a Crystal Reports directly to the client as PDF and I must must use the Export() and put the the PDF on disk first and stream to the client. That's just how it is. Question: So I need to let the aspx user have write permissions to disk.. NOT GOOD. How do I solve this? Can I somehow write the PDF to disk in another thread with other writes?...
4
2010
by: Richard506 | last post by:
If you take this Byte Arra Dim bytes() As Byte = { 207, 224, 135, 161, 253, 233, 111, 110, 99, 111, 100, 105, 110, 103, 32, 69, 120, 97, 109, 112, 108, 101 and write the byte array to disk FileOpen(2, "f:\aaapicture_album\result.txt", OpenMode.Binary FilePut(2, bytes FileClose(2 then convert it into a string --->
6
1608
by: John | last post by:
Hi I am trying to save settings of controls on my form to a file so I can read them back later and recreate the controls on the form. I have figured out how to go through all controls and get their properties (see code below). What I am not sure is; how and what type of file format I need to save the info to and how to read it back. Would appreciate any help on that. A code snippet would be very much appreciated. Many thanks
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10369
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.