Multiple Where clauses in Lambda expressions

前端 未结 5 1373
臣服心动
臣服心动 2020-12-23 13:42

I have a simple lambda expression that goes something like this:

x=> x.Lists.Include(l => l.Title).Where(l=>l.Title != String.Empty)
5条回答
  •  -上瘾入骨i
    2020-12-23 13:58

    You can include it in the same where statement with the && operator...

    x=> x.Lists.Include(l => l.Title).Where(l=>l.Title != String.Empty 
        && l.InternalName != String.Empty)
    

    You can use any of the comparison operators (think of it like doing an if statement) such as...

    List nums = new List();
    
    nums.Add(3);
    nums.Add(10);
    nums.Add(5);
    
    var results = nums.Where(x => x == 3 || x == 10);
    

    ...would bring back 3 and 10.

提交回复
热议问题