C# Compiler optimization - Unused methods

后端 未结 4 1070
Happy的楠姐
Happy的楠姐 2020-12-06 10:14

Does C# compiler (in VS2008 or VS2010) remove unused methods while compiling ?

I assume that it may have a problem deciding if public methods will ever be used, so I

4条回答
  •  情深已故
    2020-12-06 10:30

    Just checked in reflector with a release build. The compiler doesn't remove the unused private methods.

    There are ways to use a method without the compiler knowledge, like with reflection. So the compiler doesn't try to guess. It just leaves the methods there.

    The only private methods the compiler removes are partial methods without implementation.

    For the C# compiler optimizations, look here.

提交回复
热议问题