Wednesday, May 9, 2007

Problem with generic List class

Hi
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

2 comments:

luckyabhishek said...

Check the discussion on http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/56bcb9d9ac22d907/d93e3a0f82a97620?lnk=st&q=findall+generic&rnum=1&hl=en#d93e3a0f82a97620 for the solution

suraj said...

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