Usually this is done with a custom collection. Extend the CollectionBase class to create your own collection type that as custom finder methods. The methods can be implemented as standard methods or as indexers. Here's how I would implement it:
Code:
public class MyClass
{
}
public class MyClassCollection : System.Collections.CollectionBase
{
public int Add(MyClass item)
{
return this.InnerList.Add(item);
}
public MyClass FindItem(string test){
for (int i = 0; i < this.InnerList.Count; i++)
{
if(this[i].<property> == <test condition>){
return this[i];
}
}
}
public MyClass this[int index]
{
get { return (MyClass)this.InnerList[index]; }
}
public MyClass this[string test]
{
get { return FindItem(test); }
}
}
-
Peter