[02/03] Enumerating a subset of a strongly typed collection
Hi
I have a strongly typed collection of Employee objects called EmployeeCollection and the Employee object exposes a property for departmentCode. I need to do some processing on employees belonging to specific departments so I though I'd have a method that would expose a filtered view of the collection. After some digging it looks like I need to implement my own Enumeration class using IEnumerator. Can someone point me to some good code samples on how to achieve this?
I'm using VS.NET 2003
Thanks
Re: [02/03] Enumerating a subset of a strongly typed collection
I got a mail alert that jmcilhinney replied to my post but I don't see t here :(
Re: [02/03] Enumerating a subset of a strongly typed collection
I recommended that you implement the IBindingListView interface in another class, which I have done myself to provide sorting and filtering of a typed Collection. I then realised that you're on .NET 1.1 and that interface is new in .NET 2.0, so I deleted my post.
Re: [02/03] Enumerating a subset of a strongly typed collection
jmcilhinney, thanks for taking time to respond to my post.
Until I find the right way I have added an overloaded GetEnumertor method that takes department code as argument. I then initialise an EmployeeCollection object to which I add the employees who form part of the departmentcode. An the end of the method I return the newEmpCol.GetEnumerator object.
I don't quite like the idea of building another list, I would have thought of something that would have built and returned a virtual list of indexese that match the department code.
Thanks
Re: [02/03] Enumerating a subset of a strongly typed collection
Building another list is no big deal because you aren't copying the actual objects, just the references to them. That's no different to returning a list of indices as far as resources are concerned.
Re: [02/03] Enumerating a subset of a strongly typed collection
Thanks, you re-assure me in my design then.