Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7019987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:15:33+00:00 2026-05-27T23:15:33+00:00

What is the correct way to convert my class to/from a byte array? I

  • 0

What is the correct way to convert my class to/from a byte array? I want to be able to do thing like save it to a file as simply as possible.

Should I make it serializable?
Should I just supply a function that returns a byte array? Or maybe a MemoryStream?
Something else?

I am not overly familiar with C# file handling, so if the answer could also show what the common way of writing binary data to a file is, I would appreciate it.

Edit I see from the answers that I am misunderstood. I have a class. I have a format I want to save it in binary form in. I want to know what the correct way is to expose this binary representation. I need full control of the format, not .NET doing it for me (I will be reading it later in c++)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:15:34+00:00Added an answer on May 27, 2026 at 11:15 pm

    In response to your edit, and given the fact that you own the binary format and need to control it yourself, I see two options:

    • a method that accepts a stream and writes the binary representation to the stream
    • a method that returns a byte array

    Of course, you could decouple this from the type itself by creating another class with

    • a method that accepts an instance of your type and a stream and writes the binary representation to the stream
    • a method that accepts an instance of your type and returns a byte array

    The first option of each pair probably gives you more flexibility; you could pass a file stream or a memory stream or whatnot depending on your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the correct way to import a C++ class from a DLL? We're
What is the correct way to convert ASP.NET SOAP-based web services to JSON-based responses?
What is the easiest and correct way to convert a String number with commas
HI, Is there any 'correct' way to convert an XElement to an XmlNode in
What is the correct/best/simplest way to convert a c-style string to a std::string. The
I want to convert number from char * format to 32 bit integer int32_t,
I have an integer which I want to convert to class Date . I
What is the correct way to do this? For example, how would I change
What is the correct way to check if a value is a date/number in
Is there a correct way in Windows Forms to flash a titlebar without having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.