Do LINQ queries have a lot of overhead?

后端 未结 6 1890
梦毁少年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 20:59

    According to LINQ In Action (pg.198):

    "LINQ does not come for free. LINQ queries cause additional work, object creations, and pressure on the garbage collector. The additional cost of using LINQ can vary a lot depending on the query. It can be as low as 5 percent, but can sometimes be around 500 percent."

提交回复
热议问题