Lou*_*hys 2 .net c# linq sorting ienumerable
我有一个与OrderBy和ThenBy的linq查询(不是数据库相关的)
var sortedList = unsortedList
.OrderBy(foo => foo.Bar) //this property access is relatively fast
.ThenBy(foo => foo.GetCurrentValue()) //this method execution is slow
Run Code Online (Sandbox Code Playgroud)
获得foo.Bar很快,但执行foo.GetCurrentValue()速度很慢.返回值仅在某些成员具有相等的Bar值时才重要,这种情况很少发生,但在发生这种情况时需要考虑.是否可以选择仅在需要在相等Bar值的情况下进行平局时执行ThenBy子句?(即如果foo.Bar值是唯一的,则不会执行).
另外,实际上Bar也有点慢,所以最好不要为同一个对象调用它两次.
| 归档时间: |
|
| 查看次数: |
1068 次 |
| 最近记录: |