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

  • Home
  • SEARCH
  • 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 7522889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:38:27+00:00 2026-05-30T02:38:27+00:00

I am converting 2dimensional array to Single dimensional in C#. I receive the 2

  • 0

I am converting 2dimensional array to Single dimensional in C#.
I receive the 2 dimensional array from device (C++) and then I convert it to 1 dimensional in C#.
Here is my code:

int iSize = Marshal.SizeOf(stTransactionLogInfo); //stTransactionLogInfo is a structure
byte[,] bData = (byte[,])objTransLog; //objTransLog is 2 dimensionl array from device
byte[] baData = new byte[iSize];

for (int i = 0; i < bData.GetLength(0); i++)
{
    for (int j = 0; j < iSize; j++)
    {
        baData[j] = bData[i, j];
    }
}

I get the desired result from above code, but the problem is it is not the standard way of implementation.
I want to know how it can be done in a standard way.
May be doing Marshalling , I am not sure.
Thanks in advance.

  • 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-30T02:38:29+00:00Added an answer on May 30, 2026 at 2:38 am

    You can use the Buffer.BlockCopy Method:

    byte[,] bData = (byte[,])objTransLog;
    
    byte[] baData = new byte[bData.Length];
    
    Buffer.BlockCopy(bData, 0, baData, 0, bData.Length);
    

    Example:

    byte[,] bData = new byte[4, 3]
    { 
        {  1,  2,  3 }, 
        {  4,  5,  6 }, 
        {  7,  8,  9 }, 
        { 10, 11, 12 } 
    };
    
    byte[] baData = new byte[bData.Length];
    
    Buffer.BlockCopy(bData, 0, baData, 0, bData.Length);
    
    // baData == { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is converting an XML to NSString from NSData, then manipulate string and convert it
What is the best way of converting a multi-dimensional javascript array to JSON?
Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
Can anyone help with converting data from an XML document into an associative array?
I came across this function of converting a SimpleXML Object to an array here
After converting a 2D array from the CPU to the GPU's memory to run
How would one go about converting a list of integers to a two-dimensional array?
I have been converting some code from C++ to C#. My lack of understanding
Converting my current code project to TDD, I've noticed something. class Foo { public
Converting a couple stored procedures from MySQL to Microsoft SQL server. Everything is going

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.