在C#中使用'var'关键字是否会对性能产生影响? [英] Is there a performance hit in using the 'var' keyword in C#?

查看:78
本文介绍了在C#中使用'var'关键字是否会对性能产生影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
C#‘ var’与特定类型的性能

我广泛使用'var'关键字.一位同事告诉我,使用它会影响性能,但无法支持他的评论.有人知道这样的表现受到打击吗?

I use the 'var' keyword extensively. A colleague told me there was a performance hit in using it, but couldnt back up his comment. Does anyone know of such a performance hit?

推荐答案

有人问问题.简而言之,不,生成的IL代码是相同的.因此,没有任何打击.如果您想知道一种方法与另一种方法有何不同,只需编写示例,然后使用反射器来分析差异.

Someone asked that question on here already. In short, no, the IL code generated is the same. Therefore, no perf hit. If you ever wonder how one way of doing something differs from another, just write a sample and then use Reflector to analyze the differences.

这篇关于在C#中使用'var'关键字是否会对性能产生影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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