This is embarrassing. I learned C# a long time ago and am just now attempting to understand this question about classes (since they are reference types, of course).
Here’s the question: If I create two new instances of a class called Person and named one instance P and the other Q (who cares why I’d call it Q) and set P.Name to "James" and then set Q.Name to "Suzie", would P.Name be set to "Suzie"? Or am I not understanding this correctly?
Thanks everyone
Thanks everyone for helping me with this. I assumed what was explained to me was the case. But the explanations in the tutorials I read weren’t clear and I haven’t had a computer in a few months so as to have tested it out myself.
P.s I chose the first right answer that was clear to me. But noticed several. Thanks again for everyone’s help.
The short answer is NO, changing Q.Name will no affect P.Name. As in
However, if q points to the p instance, then changing q would also change p. As in:
Both q and q Name are now “Suzie”.
With data initialisers you can write the first example as:
which I think is much easier to read.