Will the compiler only compile code that can get executed?

后端 未结 6 1965
梦谈多话
梦谈多话 2020-12-15 03:37

I have a class library and am using only part of it. Is there a need to delete what isn\'t being used in order to shrink the size of the created code (in release configurati

6条回答
  •  执念已碎
    2020-12-15 03:48

    No, the compiler includes the "dead" code as well. A simple reason for this is that it's not always possible to know exactly what code will and won't be executed. For example, even a private method that is never referenced could be called via reflection, and public methods could be referenced by external assemblies.

    You can use a tool to help you find and remove unused methods (including ones only called by other unused methods). Try What tools and techniques do you use to find dead code? and Find unused code to get you started.

提交回复
热议问题