Do LINQ queries have a lot of overhead?

后端 未结 6 1881
梦毁少年i
梦毁少年i 2020-12-08 20:29

Are simple LINQ queries on an IEnumerable lightweight or heavyweight? How do they compare to writing for or foreach loops by

6条回答
  •  既然无缘
    2020-12-08 21:01

    About the only real performance overhead of LINQ-to-objects over doing it yourself are the few extra objects created to help with the enumeration and the function calls. In short, unless you use it in a way it wasn't designed to, it won't hurt your performance unless you're doing very high-perf stuff.

    In that case, I'd implement it the LINQ way first, and let your performance testing tell you in which specific places you may need to consider doing it differently. For quite a bit of code, ease of maintenance trumps pure performance.

提交回复
热议问题