I have not used structs widely in my programs, because they are value types and copy their data each time they are given to a function, but with a class with inner classes, you could make each inner class a property of the outer class with set/get accessors. Maybe only get accessors if you don't need writing access.
PHP Code:
using System;
using System.Collections;
namespace ConsoleApplication1
{
public class B
{
private string m_Name;
public B( string aName )
{
m_Name = aName;
}
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
}
public class A
{
private B m_InnerClass;
public A( string BName )
{
m_InnerClass = new B( BName );
}
public B InnerClass
{
get { return m_InnerClass; }
set { m_InnerClass = value; }
}
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
ArrayList list = new ArrayList();
for( int i = 0 ; i < 10 ; i++ )
{
// Add a new Instance of class A to the ArrayList
list.Add( new A( "Class #" + i.ToString() ) );
Console.WriteLine( "Class #" + i.ToString() + "created." );
}
Console.WriteLine( "Elements in list:" );
foreach( A Element in list )
{
// this is your C++ line:
// Element is the object
// .InnerClass calls the property and returns the Innerclass
// .Name returns the Name of the InnerClass
Console.WriteLine( Element.InnerClass.Name );
}
Console.WriteLine( "Done now, Garbage collection takes care of the rest" );
Console.Read();
}
}
}