Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda multiple conditions to select objects from List<T>

I 'm using c# to select some objects in a List. The following code is working.

public void filterByWork(string work, int precision)
        {
            workResults = new List<FbUser>();
            Array keywords = work.Split(' ');
            workResults = userlist.Where(user => user.work != null);
            workResults = workResults.Where((user => user.work.Any(wrk => StringExtensions.match(wrk.employer.name, keywords) >= precision)));

        }

But what if i want more than one condition? Can i use the 'OR' keyword somewhere? Because i want to select all objects where the wrk.employer.name = "something" OR wrk.position.name = "something". How can do this?

Thanks in advance!

like image 430
ThdK Avatar asked Mar 06 '26 17:03

ThdK


2 Answers

You can simply use the normal || operator:

workResults = workResults.Where((user => 
                  user.work.Any(wrk => wrk.employer.name == "something" || 
                                       wrk.position.name == "something")
                               ));
like image 161
Daniel Hilgarth Avatar answered Mar 08 '26 07:03

Daniel Hilgarth


Well, you could just use C#s or operator (||).

like image 40
Florian Greinacher Avatar answered Mar 08 '26 07:03

Florian Greinacher