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 6528157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:30:31+00:00 2026-05-25T09:30:31+00:00

I am reading a binary file of a specific format, and am used to

  • 0

I am reading a binary file of a specific format, and am used to being able to cast a block of data to a struct then reading the struct to pull fields out of the binary datafile.

I’m trying to do this but failing in C#, they seem more like classes than structures in the C sense. Is it possible to do what I want? For example..

public struct Datum {
    byte type;
    ushort payload;
}

public struct DiskPage {
    ushort pageNumber;
    Datum[] data = Datum[170];
}

I want to be able to read 512 bytes of a file and cast it to a DiskPage, then to be able to read the values from the DiskPage structure. Is this possible in c# – or is there another preferred approach? Should I just leave that code in C and link it in?

Thanks!
Reza

  • 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-25T09:30:31+00:00Added an answer on May 25, 2026 at 9:30 am

    I suggest you read Mastering C# structs that discusses using marshaling (Marshal.Copy in particular) for that purpose.

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

Sidebar

Related Questions

I'm reading from a binary data file which is written by invoking the following
Currently, I have been reading lists of data from a binary data file programmatically
I'm reading data out of a binary file into structs in C#. What's the
I managed to parse a large binary file (~8Gb) by reading blocks of data
In particular, I'm reading into the Mach-O binary file format for Intel 32 on
I am reading in a binary file in to a struct with StructLayout(LayoutKind.Explicit) set.
I'm reading binary data from a file, specifically from a zip file. (To know
I'm reading contents from a binary file. If I read in data elements as
I am having following issue with reading binary file in C. I have read
I am reading a binary file into a parsing program. I will need to

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.