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

查看:35
本文介绍了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 ?

是否有一组关于编译器优化的规则记录在任何地方?

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# 编译器优化,请查看 此处 (archive.org).

For the C# compiler optimizations, look here (archive.org).

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

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