Storing Objects in Objects

  • Thread starter Thread starter Jim Bayers
  • Start date Start date
J

Jim Bayers

I'm new at working with object oriented programming. Here's what I want to
do.

Create three objects of the same class, A, B and C. These will live the
life of the program. I want to be able to store A in B, by referrence or
otherwise, and then retrieve A at a later point.

I can create the class and then create a new object, but I can't store A in
B, and forget about retrieving A.

Could you post a brief example?
 
In C# you can do something like this.

I would recommend C# over VB.NET for learning object-oriented programming since the syntax is simpler.

Not exactly sure just what you're trying to accomplish. You might want to look into using container classes.

namespace N
{
public class CLASS
{
public CLASS c;
}

[STAThread]
static public void Main()
{
CLASS A, B, C;

B = new CLASS();
B.c = new CLASS();
C = new CLASS();
}
}
 
Hi Jim,

You mean such a simple approach as this?
Public Module Main
Public Sub Main()
Dim A As New ABC
Dim B As New ABC
Dim C As New ABC
A.val = "0"
B.val = A
C.val = B
A.val = "2"
MessageBox.Show(DirectCast(DirectCast(DirectCast(C, ABC).val,
ABC).val,ABC).val.ToString)
End Sub
Public Class ABC
Public val As Object
End Class
End Module

The result of this is 2.

I hope this gives an idea?

Cor
 
Back
Top