1.In
1). Add range. 相当于in.
var listForStatus = new List<DTO_FlightAndPrice>();
if (checkedStatus != null && checkedStatus.Count() > 0)
{
foreach (string s in checkedStatus)
{
if (listForWeekdays.Where(c => c.FlightInfo.CalculateStatus.Contains(s)) != null)
{
listForStatus.AddRange(listForWeekdays.Where(c => c.FlightInfo.CalculateStatus != null && c.FlightInfo.CalculateStatus.Contains(s)).ToList());
}
if (listForWeekdays.Where(c => c.FlightInfo.PriceStatus.Contains(s)) != null)
{
listForStatus.AddRange(listForWeekdays.Where(c => c.FlightInfo.PriceStatus != null && c.FlightInfo.PriceStatus.Contains(s)).ToList());
}
}
}
2). in 的另一种。
What is the syntax for comparing against a predefined list? Something like:
int[] listofIds = GetListofIds();
list.Where(r => r.Id "in listofIds");
should be:
list.Where(r => listofIds.Contains(r.Id))
2.or
LINQ查询表达式:from truck in TB_CX_TRUCKs where 1==1 ||truck.LICENSE_NUMBER.Length<10 select truck
LINQ等价的链式方法:TB_CX_TRUCKs.Where (truck => (True || (truck.LICENSE_NUMBER.Length < 10)))