C# 是否优化级联调用的重载方法?
我有一些这样的代码:
class MainApplication {
protected static string _since;
protected static void updateSince()
{
MainApplication.updateSince(DateTime.Now);
}
public static void updateSince(DateTime since)
{
MainApplication.updateSince(since.ToString("yyyy-MM-dd HH:mm:ss"));
}
public static void updateSince(string since)
{
// finally, doing something real
MainApplication._since = since;
}
/* ... */
}
我想知道 C# 是否以及如何优化此类级联调用?
I have some code like that:
class MainApplication {
protected static string _since;
protected static void updateSince()
{
MainApplication.updateSince(DateTime.Now);
}
public static void updateSince(DateTime since)
{
MainApplication.updateSince(since.ToString("yyyy-MM-dd HH:mm:ss"));
}
public static void updateSince(string since)
{
// finally, doing something real
MainApplication._since = since;
}
/* ... */
}
And I wonder if and how C# optimizes such cascade call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,C# 根本不优化东西。你问的是,编译器是否优化了这个...
编译器不会对此进行“优化”。您可以在查看生成的 IL 代码时验证这一点。
No, C# doesn't optimize stuff at all. What you are asking is, whether the compiler optimizes this...
The compiler doesn't "optimize" this. You can verify this when you have a look at the generated IL code.