With C# in VS2017, if I don't want to comment out a method (or class) which is not used, will it be optimized out and not included in the assembly? Or will it stay in the assembly, taking up space?
It is in the build because the compiler doesn’t know if it is used or not at runtime; if the assembly is a class library, it can be referenced by other assemblies, and the code can be used (if the class and method are public), so compiler will not optimize the unused code out.
You can use “#if DEBUG” and “#endif” to wrap the unused code, then it will not be compiled into the release build. DEBUG symbol is not defined in release configuration, so the compiler knows you don’t want to include the code in release build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With