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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:38:11+00:00 2026-05-16T06:38:11+00:00

I am creating an array as below: public struct Smb_Parameters { public byte WordCount;

  • 0

I am creating an array as below:

public struct Smb_Parameters
        {
            public byte WordCount;
            public ushort[] Words;
        }

While I assign the values Like below:

Smb_Parameters smbParameter = new Smb_Parameters();
smbParameter.WordCount = 0;
string words= "NT LM 0.12";
smbParameter.Words = Encoding.ASCII.GetBytes(name);

In the above assignment smbParameter.WordCount contains the value 0 but does smbParameter.Words contains directly the values(Arry of byteS) or memory reference to the location that contains the values?

Edit 1:

I want to send a packet to the server . For that I need to convert Smb_Parameters object to array using the following code:

int len = Marshal.SizeOf(Smb_Parameters);
 byte[] arr = new byte[len];
 IntPtr ptr = Marshal.AllocHGlobal(len);
 Marshal.StructureToPtr(Smb_Parameters, ptr, true);
 Marshal.Copy(ptr, arr, 0, len);
 Marshal.FreeHGlobal(ptr);
  • 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-16T06:38:11+00:00Added an answer on May 16, 2026 at 6:38 am

    Unless you use fixed-size buffers in unsafe code, it will be a reference. In general, it doesn’t matter whether a variable is contained within a struct or a class – or indeed whether it’s a local variable: the type of the variable decides whether the value is a reference or whether it contains the data directly. Aside from the fixed-size buffers I’ve mentioned, arrays are always reference types in .NET.

    (There’s also stackalloc which looks a bit like an array allocation – it allocates a block of memory on the stack. Again, this is only for use in unsafe code, and very rarely encountered in my experience.)

    In the example you’ve given (suitably adjusted to make it compile) Words would definitely be a reference. In particular, if you assign the value to refer to a particular array and then change the contents of that array, the changes will be visible via the struct’s variable.

    (I’d also strongly recommend that you don’t have public fields or mutable value types. Hopefully this was just for the sake of an example though 🙂

    EDIT: To answer the updated question, don’t send data like that. It’s a horribly fragile way of serializing anything. There are various better options:

    • Use .NET binary serialization (also somewhat fragile in terms of versioning, and not cross-platform)
    • Use XML serialization (probably overkill in this case)
    • Use a third-party serialization framework (e.g. Thrift or Protocol Buffers)
    • Hand-roll serialization with a “ToByteArray” or “WriteToStream” method in your class which serializes each value explicitly. You might want to use BinaryWriter for this.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can you put an array to the WHERE -clause below without creating 50
So I'm creating an array called fruits which I would like to share between
What is the prefered method for creating a byte array from an input stream?
See the code example below: public function buildForm(FormBuilder $builder, array $options) { $builder->add('firstname'); $builder->add('lastname');
please tell me what is below code doing? is it creating array with two
I am creating an array to store in cookie using jquery.cookies.js Below is the
I am creating an array of string objects in PowerShell which needs to be
I'm creating an array of view controllers, adding them to a UINavigation Controller, and
Why is it that for user defined types when creating an array of objects
what i want to do is that i am creating php array dynamic .i

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.