Jump to content

How to easily write to binary file in c#

Cy-Fy

Hello guys I'm creating an application and I need to store user details as a binary file.

 

I did this very simply by writing a text file but in the file extension I wrote .bin which seemed to somewhat work.

 

Is this okay? Because my teacher recommended me to use a "serialiazer" or something similar but my solution seems to be the easiest.

 

Thanks very much!

Dell XPS 15 9560 - Nikon Z5 - Galaxy S10+

Link to comment
Share on other sites

Link to post
Share on other sites

If you do what you did, it won't necessarily be compatible with other programs and such that use regular, serialized .bin files. The formatting will be wrong. If it's just for you, from one program you wrote to another, or better yet, withing a single program, it won't matter. You can yourself make the formatting compatible. But the .bin -extension will be pretty much in vain then too. You could just as well make it .awesomeextension if you felt like. I myself use the .naeaes extension whenever I get a chance. :D 

 

EDIT: Oh, here's an actually understandable description at MSDN. Go figure. :)

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Naeaes said:

If you do what you did, it won't necessarily be compatible with other programs and such that use regular, serialized .bin files. The formatting will be wrong. If it's just for you, from one program you wrote to another, or better yet, withing a single program, it won't matter. You can yourself make the formatting compatible. But the .bin -extension will be pretty much in vain then too. You could just as well make it .awesomeextension if you felt like. I myself use the .naeaes extension whenever I get a chance. :D 

 

EDIT: Oh, here's an actually understandable description at MSDN. Go figure. :)

Thanks I sort of get it now but I'm still wondering if what I'm doing does count as serialization or not. And yeah it is simply to store usernames that will only be used by the same program.

Dell XPS 15 9560 - Nikon Z5 - Galaxy S10+

Link to comment
Share on other sites

Link to post
Share on other sites

Could you show your current code? Hard to exactly what you have done from your description :)

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, MSVSora said:

Could you show your current code? Hard to exactly what you have done from your description :)

Hi sorry I can't at the moment as I am on my phone.. what I'm saying is that I simply did this:

File.WriteAllLines(filename.bin)

 

Edit: or with the usernames to write inside the brackets and filename.bin as the path but you get what I mean my point is that the file is not .txt but .bin

Dell XPS 15 9560 - Nikon Z5 - Galaxy S10+

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Cy-Fy said:

Thanks I sort of get it now but I'm still wondering if what I'm doing does count as serialization or not. And yeah it is simply to store usernames that will only be used by the same program.

I don't think so. I'm not fluent in C# so I really don't know, but according to this you need to do the thing with BinaryFormatter.Serialize()

Try it out and see how the resulting .bin is different from what you got this far. I'd imagine it's all just to hide the plain text or something.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Naeaes said:

I don't think so. I'm not fluent in C# so I really don't know, but according to this you need to do the thing with BinaryFormatter.Serialize()

Try it out and see how the resulting .bin is different from what you got this far. I'd imagine it's all just to hide the plain text or something.

Haha I'm confused bu thanks anyway :) I'll play around with it and see what I get

Dell XPS 15 9560 - Nikon Z5 - Galaxy S10+

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×