D
D
Dmitry Gavrilenko2015-01-25 19:32:02
.NET
Dmitry Gavrilenko, 2015-01-25 19:32:02

It is impossible to change the data in the structure directly?

f602b751149d41e694ff9f61392557d7.PNG
Company is a structure. Owner and CompanyName are properties.
Error: Failed to change return value for '*.Company' because it is not a variable
Question: is it forbidden to change the data in the structure, on a straight line?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mrrl, 2015-01-25
@Maddox

I assume that the Company field in the Im.Work object is also described as a property:
public Company Company{ get; set; }
In this case, when you write Im.Work.Company.CompanyName="Name", the get method for Company is called, returns a copy of the structure (because it cannot return a reference), and then you try in this copy without putting it anywhere , change one of the fields. The original will definitely not change from this, and, apparently, the compiler does not allow you to perform a deliberately meaningless action (change the object that will now be destroyed).

A
Aristarkh Zagorodnikov, 2015-01-25
@onyxmaster

No readonly modifier?

D
Dmitry Gavrilenko, 2015-01-25
@Maddox

public struct Company
    {
        public string CompanyName { get; set; }
        public Build Build { get; set; }
        public Human Owner { get; set; }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question