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 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

If have a union that currently foresees some simple data types: union Value {
Edit2: Can I do polymorphism with Union? It seems to me that I can
I've got some code originating from a DSL that needs to be translated for
I've got some code that I've been using successfully for some years to implement
I have a struct where a constant char string is defined and a pointer
Hey! I know title of question is very scary but I still I am
NOTE: This question changed a little as I learned more about the problem, so
I have been reading an article about Lockless Programming in MSDN. It says :
I'm trying to create a class to use as a field in other objects
I was reading about Empty Base Optimization(EBO). While reading, the following questions popped up

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.