Is there any overhead in the use of anonymous methods?

后端 未结 8 1950
遇见更好的自我
遇见更好的自我 2021-02-15 17:27

I would like to know if there is any overhead incurred through the use of anonymous methods when creating a Background worker.

for example:

public void S         


        
8条回答
  •  萌比男神i
    2021-02-15 17:43

    Whenever an anonymous method (incl lambdas) close over variables the compiler creates a class to hold these variables for you. Whenever the delegate is created a new instance of this class is too. This obviously adds extra work for the runtime, but is generally negligible in most situations.

提交回复
热议问题