Performance of anonymous types in C#

后端 未结 5 1733
傲寒
傲寒 2020-12-20 13:03

Is it bad to use anonymous types in C#?

5条回答
  •  情话喂你
    2020-12-20 13:48

    They're like other types, in terms of performance.

    edit

    To be more clear, I should have said that they perform exactly like other types because they are exactly like other types, except for the fact that the compiler generates the name. The only way performance would suffer is if you pass an instance of the anonymous type to another scope, where reflection or dynamic would have to be used just to access the properties. That would be expensive because it involves late binding to resolve everything at runtime.

提交回复
热议问题