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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:30:06+00:00 2026-05-13T13:30:06+00:00

Take the following struct class: public struct SingleWraper { private double _myValue; public double

  • 0

Take the following struct class:

public struct SingleWraper
{
    private double _myValue;

    public double MyValue
    {
        get { return _myValue; }
        set { _myValue = value; }
    }

    public void SetMyValue(double myValue)
    {
        _myValue = myValue;
    }
}

public struct DoubleWraper
{
    public SingleWraper SingWraper { get; set; }

    public void SetMyValue(double singleVa)
    {
        SingWraper.SetMyValue(singleVa);
    }
}

Run the following test:

    [Test]
    public void SetMyValue()
    {
        var singleWraper = new DoubleWraper();
        singleWraper.SetMyValue(10);
        Assert.AreEqual(10,singleWraper.SingWraper.MyValue);
    }

It fails.

However, if you don’t use automatic property for DoubleWraper, i.e, you expand the field as below:

public struct DoubleWraper
{
    private SingleWraper _singWraper;
    public SingleWraper SingWraper
    {
        get { return _singWraper; }
        set { _singWraper = value; }
    }

    public void SetMyValue(double singleVa)
    {
        _singWraper.SetMyValue(singleVa);
    }
}

Then the test will pass.

Why this is so?

  • 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-13T13:30:06+00:00Added an answer on May 13, 2026 at 1:30 pm

    It is here:

    _singWraper.SetMyValue(singleVa);
    

    vs:

    SingWraper.SetMyValue(singleVa);
    

    In the second, you access a property, therefore you clone the struct; essentially this is the same as:

    var clonedAndIndependentValue = SingWraper; // getter
    clonedAndIndependentValue.SetMyValue(singleVa);
    

    Note we’ve updated a different struct value; contrast to field access, which talks to the existing struct value.

    Yet another example of why mutable structs are evil. DON’T DO IT. Make the struct immutable (no Set* methods, property setters, or other shenanigans). Or use a class.

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

Sidebar

Ask A Question

Stats

  • Questions 531k
  • Answers 531k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer These pages show all the attributes you can apply to… May 16, 2026 at 11:56 pm
  • Editorial Team
    Editorial Team added an answer You need to download and install the db2 client only.… May 16, 2026 at 11:56 pm
  • Editorial Team
    Editorial Team added an answer you can use trigger in MySQL instead of procedure. The… May 16, 2026 at 11:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

take two following classes: class Test1{ public: Test1()=default; Test1(char in1,char in2):char1(in1),char2(in2){} char char1; char
Take the following simple source (name it test.cpp): #include <windows.h> void main() { DebugBreak();
I have a template class which looks like the following: template <template <class TypeT>
I’d like to declare a generic class Simple where a method called Addition would
Consider a class Calendar that stores a bunch of Date objects. The calendar is
As someone who is attempting to take a more object oriented approach to my
I just simply want to retrieve two substring of a string which take the
I'd like to have a list that will shorten a field value if it
I am calling into a native dll from C#. For the specific function in
I've recently encountered a situation where I need to create a generic method 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.