如何在C#中从列表中选择元素时排除整数范围?

如何在C#中从列表中选择元素时排除整数范围?,c#,asp.net-mvc,C#,Asp.net Mvc,我目前正在编写一个应用程序,可以提取一定数量的飞行记录。以下代码工作正常: foreach (var rec in record .Skip(GetFlightIndex()) .Take((int)AppDefaults.NumFlights)) 现在,我想排除航班号在一定范围内的航班记录(如包机等),因为某些原因,该代码不起作用。你有没有想过为什么会这样 foreach(var rec in records

我目前正在编写一个应用程序,可以提取一定数量的飞行记录。以下代码工作正常:

        foreach (var rec in record
            .Skip(GetFlightIndex())
            .Take((int)AppDefaults.NumFlights))
现在,我想排除航班号在一定范围内的航班记录(如包机等),因为某些原因,该代码不起作用。你有没有想过为什么会这样

        foreach(var rec in records
            .Skip(GetFlightIndex())
            .Take((int)AppDefaults.NumFlights)
            .Where( i =>
                Int32.Parse(i.FLIGHTNO) < 700 && Int32.Parse(i.FLIGHTNO) > 799 &&
                Int32.Parse(i.FLIGHTNO) < 900 && Int32.Parse(i.FLIGHTNO) > 999 &&
                Int32.Parse(i.FLIGHTNO) < 1900 && Int32.Parse(i.FLIGHTNO) > 1999 &&
                Int32.Parse(i.FLIGHTNO) < 8000 && Int32.Parse(i.FLIGHTNO) > 9799 &&
                Int32.Parse(i.FLIGHTNO) < 9900 && Int32.Parse(i.FLIGHTNO) > 9999 ))
foreach(记录中的var rec
.Skip(GetFlightIndex())
.Take((int)AppDefaults.NumFlights)
.其中(i=>
Int32.Parse(i.FLIGHTNO)<700&&Int32.Parse(i.FLIGHTNO)>799&&
Int32.Parse(i.FLIGHTNO)<900&&Int32.Parse(i.FLIGHTNO)>999&&
Int32.Parse(i.FLIGHTNO)<1900&&Int32.Parse(i.FLIGHTNO)>1999&&
Int32.Parse(i.FLIGHTNO)<8000&&Int32.Parse(i.FLIGHTNO)>9799&&
Int32.Parse(i.FLIGHTNO)<9900&&Int32.Parse(i.FLIGHTNO)>9999)

where子句中的逻辑不太正确。以下情况永远不可能是真的:

Int32.Parse(i.FLIGHTNO) < 700 && Int32.Parse(i.FLIGHTNO) > 799
Int32.Parse(i.FLIGHTNO)<700&&Int32.Parse(i.FLIGHTNO)>799
你可能是说:

Int32.Parse(i.FLIGHTNO) > 700 && Int32.Parse(i.FLIGHTNO) < 799
Int32.Parse(i.FLIGHTNO)>700&&Int32.Parse(i.FLIGHTNO)<799
此外,数字不能介于700-799和900-999之间。。因此,您需要在每个范围之间设置OR

Int32.Parse((i.FLIGHTNO) > 700 && Int32.Parse(i.FLIGHTNO) < 799) ||
Int32.Parse((i.FLIGHTNO) > 900 && Int32.Parse(i.FLIGHTNO) < 999) ||
Int32.Parse((i.FLIGHTNO) > 1900 && Int32.Parse(i.FLIGHTNO) < 1999) ||
Int32.Parse((i.FLIGHTNO) > 8000 && Int32.Parse(i.FLIGHTNO) < 9799) ||
Int32.Parse((i.FLIGHTNO) > 9900 && Int32.Parse(i.FLIGHTNO) < 9999)
Int32.Parse((i.FLIGHTNO)>700&&Int32.Parse(i.FLIGHTNO)<799)||
Int32.Parse((i.FLIGHTNO)>900&&Int32.Parse(i.FLIGHTNO)<999)||
Int32.Parse((i.FLIGHTNO)>1900&&Int32.Parse(i.FLIGHTNO)<1999)||
Int32.Parse((i.FLIGHTNO)>8000&&Int32.Parse(i.FLIGHTNO)<9799)||
Int32.Parse((i.FLIGHTNO)>9900&&Int32.Parse(i.FLIGHTNO)<9999)

最后,您可能希望先过滤,然后获取页面的数据,而不是像现在这样——先获取页面数据,然后过滤。要更改此移动,请在
Skip()

之前移动
Where()
“不起作用”是什么意思?感谢您告诉我这一点,我实际上是想排除这些范围,因此此逻辑最终起作用:Int32.Parse(I.FLIGHTNO)<700 | | Int32.Parse(I.FLIGHTNO)>799&。。。