我目前正在编写一个应用程序,可以获取一定数量的飞行记录。以下代码运行正常:
        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 ))发布于 2014-07-02 00:59:09
where子句中的逻辑不太正确。下列情况永远不可能是真的:
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)最后,你可能想要过滤,然后得到页面的数据,而不是相反的方式,因为你有它--得到页面数据然后过滤。若要更改此操作,请在Where()之前移动Skip()
https://stackoverflow.com/questions/24521307
复制相似问题