请问var关键字在C#原因拳击? [英] Does var keyword in C# cause boxing?

查看:91
本文介绍了请问var关键字在C#原因拳击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的老板不许我使用 VAR ,因为它会导致拳击和放缓的应用程序。

My boss forbids me to use var as it would cause boxing and slowing down the app.

是这样吗?

推荐答案

这是方法可能会工作这两种方法写的:

An approach that might work is to write these two methods:

public static void WithInt()
{
    int x = 5;
    Console.WriteLine(x);
}

public static void WithVar()
{
    var x = 5;
    Console.WriteLine(x);
}



编译,并使用反汇编检查生产CIL。显示你的老板。

Compile, and use ildasm to examine the produced CIL. Show your boss.

修改 @ CK所做的一切,但最后一步你:)

这篇关于请问var关键字在C#原因拳击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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