یک پروژه Console App ایجاد کرده و کدهای زیر رو در اون copy\paste کنید:
using System;
class Program
{
static void Main (string [] args)
{
A a = new A ();
string b1 = a.Data ["b1"].Value;
string b2 = a.Data ["b2"].Value;
Console.WriteLine (b1 + " : " + b2);
Console.ReadKey ();
}
}
class A
{
private BCollection collect = new BCollection ();
public BCollection Data
{
get
{
return this.collect;
}
}
}
class BCollection
{
private B
b1 = new B ("Hello"),
b2 = new B ("Bye");
public B this [string name]
{
get
{
switch (name.ToUpper())
{
case "B1":
return b1;
case "B2":
return b2;
default :
throw new ArgumentException (name + " not found");
}
}
}
}
class B
{
private string _value;
public B (string value)
{
this._value = value;
}
public string Value
{
get
{
return this._value;
}
}
}
موارد مهم رو بصورت bold (تو پر و غلیظ) مشخص کردم. امیدوارم کدها رو خوانا نوشته باشم...