过滤多列上的列表

Pre*_*ent 1 c# linq asp.net

我需要根据多个列过滤我的列表.这是我需要搜索的课程

public class psdata
    {
        public int ID { get; set; }
        public string Customer { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Zip { get; set; }
        public decimal? Identification { get; set; }
        public decimal? Assesment { get; set; }
        public decimal? PayoffLedger { get; set; }
        public decimal? RentRestrictions { get; set; }
        public decimal? CCR { get; set; }
        public decimal SubTotal { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

这是我的linq查询查看我的列表,然后将找到搜索项,如果它包含在列中.

var sl = list.Where<psdata>( c => c.Address.ToLower().Contains(text));
Run Code Online (Sandbox Code Playgroud)

这适用于第一列.但是,如果我想添加另一列,那么.

var sl = list.Where<psdata>( c => c.Address.ToLower().Contains(text) || c => c.City.ToLower().Contains(text));
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

Operator || cannot be applied to operands of the type bool and psdata.
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

Jus*_*ner 6

你唯一的问题是第二个问题c =>.你仍然只传递一个Lambda表达式,它只需要包含||运算符:

var sl = list.Where(c => c.Address.ToLower().Contains(text) ||
    c.City.ToLower().Contains(text));
Run Code Online (Sandbox Code Playgroud)