I have a collection in c#
For ex:
Collection<User> List = null;
I need to filter it based on sum parameters. so lets say i want to filter out users whos userID is between 1 to 100.
Please advice how i can do this in c#
Thanks
Amit
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you’re using .NET 3.5 or higher, and you don’t need the filtering to be in place, just use LINQ:
Note that this is filtering out users with IDs between 1 and 100 rather than filtering them in as per other answers.
If this doesn’t help, please clarify the question. (Out of interest, why are you using
Collection<T>to start with?)EDIT: If you really need a
Collection<T>you can create one easily enough:You could even add your own
ToCollectionextension method to make this simpler. ButCollection<T>is usually meant to be the base class for more specific collection types (e.g.ObservableCollection<T>) – it’s odd to be constructing one directly. If your API is written in terms ofCollection<T>, you should potentially change it to be written in terms ofIList<T>, giving you more flexibility.