Using more than one condition in linq's where method

前端 未结 7 1410
南方客
南方客 2020-12-15 15:44

I have a line of code using where:

codebase.Methods.Where(x => x.Body.Scopes.Count > 5);

How can I insert more than one condition? So

7条回答
  •  时光说笑
    2020-12-15 16:02

    no you can't define 2 delegates in the same where but you can build after each other or put both on same condition like this

     var result = codebase.Methods.Where(x => x.Body.Scopes.Count > 5 && x.Body.Scopes.name == "" );
    
    or 
    
     var result = codebase.Methods.Where(x => x.Body.Scopes.Count > 5 )
            .where( y=> y.Body.Scopes.name == '' );
    
    or 
    
     var result = codebase.Methods.Where(x => x.Body.Scopes.Count > 5  )
    .Union( codebase.Methods.Where(y => y.Body.Scopes.name == ''  ) );
    

提交回复
热议问题