Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个列表,我正在迭代如下。
foreach (Statistics value in data.Where(x => x.DateOrTime >= start[0]))
但是,我想添加一个检查 myVariable == 0 然后按照上面的方式进行。否则按如下方式进行。
foreach (Statistics value in data)
所以基本上,我想在表达式中做一个 if/else。
怎么样:
foreach (Statistics value in data.Where(x => myVariable != 0 || x.DateOrTime >= start[0]))
或者:
var query = myVariable == 0 ? data.Where(x => x.DateOrTime >= start[0]) : data; foreach (Statistics value in query) { }