Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class C
- {
- public Foo Foos[int i]
- {
- ...
- }
- public Bar Bars[int i]
- {
- ...
- }
- }
- public IList<Foo> Foos
- {
- get { return ...; }
- }
- public IList<Bar> Bars
- {
- get { return ...; }
- }
- C whatever = new C();
- Foo myFoo = whatever.Foos[13];
- var myClass = new MyClass();
- Console.WriteLine(myClass.Foos[0]);
- Console.WriteLine(myClass.Bars[0]);
- public class C {
- private string[] foos = new string[] { "foo1", "foo2", "foo3" };
- private string[] bars = new string[] { "bar1", "bar2", "bar3" };
- public string[] Foos { get { return foos; } }
- public string[] Bars { get { return bars; } }
- }
- C myThing = new C();
- Console.WriteLine(myThing.Foos[1]);
- Console.WriteLine(myThing.Bars[2]);
- public class MultiIndexer : List<string>
- {
- public string this[int i]
- {
- get{
- return this[i];
- }
- }
- public string this[string pValue]
- {
- get
- {
- //Just to demonstrate
- return this.Find(x => x == pValue);
- }
- }
- }
- public struct EmployeeId
- {
- public int val;
- public EmployeeId(knt employeeId) { val = employeeId; }
- }
- public struct HRId
- {
- public int val;
- public HRId(knt hrId) { val = hrId; }
- }
- public class Employee
- {
- public int EmployeeId;
- public int HrId;
- // other stuff
- }
- public class Employees: Collection<Employee>
- {
- public Employee this[EmployeeId employeeId]
- {
- get
- {
- foreach (Employee emp in this)
- if (emp.EmployeeId == employeeId.val)
- return emp;
- return null;
- }
- }
- public Employee this[HRId hrId]
- {
- get
- {
- foreach (Employee emp in this)
- if (emp.HRId == hrId.val)
- return emp;
- return null;
- }
- }
- }
- Employee Bob = MyEmployeeCollection[new EmployeeID(34)];
Add Comment
Please, Sign In to add comment