// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; namespace E { public class Person { public string Name { get; set; } public string Address { get; set; } public override string ToString() { return "{" + Name + "," + Address + ")"; } } public class Job { public string Title { get; set; } public decimal Salary { get; set; } public override string ToString() { return "{" + Title + "," + Salary + ")"; } } public class PersonList { private List data = new List(); public void Add(Person p) { data.Add(p); } public Person this[int ix] { get { return data[ix]; } } } public class JobList { private List data = new List(); public void Add(Job j) { data.Add(j); } public Job this[int ix] { get { return data[ix]; } } } public class Index { public int Ix { get; set; } } public class PersonIndex : Index { } public class JobIndex : Index { } public class EmployeeList { private PersonList persons = new PersonList(); private JobList jobs = new JobList(); public void Add(Person p, Job j) { persons.Add(p); jobs.Add(j); } public Person GetPerson(int ix) { return persons[ix]; } public Job GetJob(int ix) { return jobs[ix]; } public Person this[PersonIndex ix] { get { return GetPerson(ix.Ix); } } public Job this[JobIndex ix] { get { return GetJob(ix.Ix); } } } public class Program { public static void Main(string[] args) { EmployeeList lst = new EmployeeList(); lst.Add(new Person{ Name="A A", Address="A road 123"}, new Job{ Title="Developer", Salary=10000.00m}); lst.Add(new Person{ Name="B B", Address="B ave 456"}, new Job{ Title="Tester", Salary=9000.00m}); Console.WriteLine(lst.GetPerson(0)); Console.WriteLine(lst.GetJob(1)); Console.WriteLine(lst[new PersonIndex{ Ix=0 }]); Console.WriteLine(lst[new JobIndex{ Ix=1 }]); } } }