Questions tagged «filtering»

2
使用where条件vs Continue保护子句过滤foreach循环
我已经看到一些程序员使用此: foreach (var item in items) { if (item.Field != null) continue; if (item.State != ItemStates.Deleted) continue; // code } 而不是我通常使用的位置: foreach (var item in items.Where(i => i.Field != null && i.State != ItemStates.Deleted)) { // code } 我什至看到了两者的结合。我真的很喜欢“继续”的可读性,尤其是在更复杂的条件下。性能上甚至有差异吗?通过数据库查询,我假设会有。常规列表呢?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.