C#编译器的优化 - 未使用方法 [英] C# Compiler optimization - Unused methods

查看:234
本文介绍了C#编译器的优化 - 未使用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问C#编译器(在VS2008或VS2010),而编制删除未使用的方法是什么?

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 guess it will compile all the public methods.

但是对于那些从来类内部使用的私有方法呢?

But what about private methods that are never used inside a class ?

编辑:

是否有任何地方都记录了一系列关于编译器的optmization规则?

Are there a set of rules about the compiler's optmization that are documented anywhere ?

推荐答案

在反射刚才检查了发布版本。编译器的删除未使用的私有方法。

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.

对于C#编译器优化,看<一个href=\"http://blogs.msdn.com/b/ericlippert/archive/2009/06/11/what-does-the-optimize-switch-do.aspx\">here.

For the C# compiler optimizations, look here.

这篇关于C#编译器的优化 - 未使用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆