|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Objects owner (C#)
I've got two classes, one of which is a member of the other.
Code:
public class MyClass
{
// Fields, Constructors, Methods, etc...
}
public class OwnerClass
{
// Fields, Constructors, Methods, etc...
public MyClass MemberClass;
}
|
|
#2
|
|||||
|
|||||
|
This is one way, at least:
C# Code:
I am not sure if there are better ways. |
|
#3
|
|||
|
|||
|
I had been under the mistaken impression that declaring an object in a class in such a way made a separate copy of that object. After a little more research it's clear that an object that I make in this way is really only a reference to the object that it's set to. In other words, if I change the original OwnerClass object independently of the MyClass object, it's automatically reflected in the MyClass object because it's only a reference. This makes things a whole lot easier than I thought they would be.
If I'm wrong about that please let me know. I'll take a lack of response as acknowledgment that my understanding is correct. |
|
#4
|
|||
|
|||
|
> I'll take a lack of response as acknowledgment that my understanding is correct
Or maybe someone could be too lazy or busy to reply back. ![]() A class is a reference type, so you would only pass a reference to it; not make a copy of it. Anyone, please correct me if I am wrong. ![]() |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Objects owner (C#) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|