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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:02:26+00:00 2026-05-22T01:02:26+00:00

How the struct data-type can still be a value type when it has a

  • 0

How the struct data-type can still be a value type when it has a property that is Reference Type?

Is it in real a reference type which is somehow processed with a value type behavior?

  • 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-22T01:02:27+00:00Added an answer on May 22, 2026 at 1:02 am

    It’s simple, really. The field in the struct simply contains a reference to the object that is a reference type. If you’re familiar with other languages like C or C++, you might recognize this immediately as being similar to a “pointer”, which is essentially a value containing the memory address at which the object being “pointed to” resides.

    It doesn’t consume any more memory because the struct is only storing a reference to the object, not a complete copy of the object. And when there are no longer any references to that object, it will become eligible for garbage collection.

    You might think of this as being similar to how a reference object can be passed “by value”. In VB.NET, this is explicitly indicated with the use of the ByVal keyword. In C#, passing objects by value is simply the default, and you have to indicate explicitly that you want them passed by reference using ref. Either way, the point is that a reference object can still be passed “by value” because all that’s being passed is a copy of the reference, not a copy of the entire object.

    Of course, one of the joys of managed environments like .NET is that you don’t have to worry about any of these implementation details. Your code will work just fine if you have a struct containing fields that represent both value types and reference types.

    Also see my answer to this very similar question: Does it make sense to define a struct with a reference type member? It’s worth considering whether or not you really need to define a struct in the first place. Most of the time, a class is a better choice. But whichever one you choose, the behavior in terms of fields containing reference types will be the same.

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

Sidebar

Related Questions

I have a code that looks something like: struct Data { int value; };
I have a data type and I can instantiate a variable of that type.
Is there something like struct data type in PHP? Can anyone give me example
There is a simple POD data type like struct Item { int value1; double
I pass the custom data type of C# struct and now I want to
I want to write a linked list that can have the data field store
My struct looks like this: struct tlv_msg { uint8_t datatype; //type of data /*
If have a union that currently foresees some simple data types: union Value {
I must write array of struct Data to hard disk: struct Data { char
I've got something like: typedef struct Data_s { int field1; int field2; } Data;

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.