Using partial classes

纵然是瞬间 提交于 2019-12-12 10:37:08

问题


Is there any overhead using partial classes in case of memory, performance etc?

If we create a partial class can we identify whether the class was partial or not using reflector??


回答1:


No. They are compiled to the same IL as if they weren't partial. It's a purely compile-time thing - the CLR doesn't even know that they were ever partial.

Note that with partial methods introduced into C# 3, the method doesn't even get emitted in the IL unless it's implemented in one of the files. Both the calls and the declaration get stripped out by the compiler.

It's possible that it'll slow down the compiler an imperceptible fraction of a millisecond, of course :)




回答2:


No, all class files will get consolidated at compile time.

Here's the msdn article on partial types.

Each source file contains a section of the type or method definition, and all parts are combined when the application is compiled.




回答3:


No. They are compiled into one class. It is purely a language feature.



来源:https://stackoverflow.com/questions/1048642/using-partial-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!