Wednesday, May 9, 2007

Problem with generic List class

I am using a generic list in my program to have a list of objects stored. I want to compare all the objects in this list with object of another class and find all the objects which meet the criteria. To make it more specific I have a class Employee and a class Salary which look like
Employee { Name Salary Age Id}
Salary{ Currency Amount}

Now i am having a List and when now what i want is to get a List of Employees whose salary is greater then 2000. One way to achieve this is to write a method in class Salary which looks like
public bool IsGreaterThen2000(Employee obj)
{ //some logic return true/false;}

and then pass this as predicate to FindAll method however the responsibility of comparison lies with Salary class. I want to shift this responsibility to some other class which already has the logic for comparison. Is there a way to achieve this using existing generic List class in .NET framework.

Any good ideas out there to solve this with .NET framework 2.0 ?????



Abhishek said...

Check the discussion on for the solution

suraj said...

Kya kya liktha rahata hai be,writer ban gaya hai re tu