问题:
Earlier I asked a question about why I see so many examples use the var
keyword and got the answer that while it is only necessary for anonymous types, that it is used nonetheless to make writing code 'quicker'/easier and 'just because'.早些时候我问了一个问题, 为什么我看到这么多例子使用var
关键字,并得到了答案,虽然它只对匿名类型是必需的,但它仍然用于使编写代码“更快”/更容易和“只是因为”。
Following this link ("C# 3.0 - Var Isn't Objec") I saw that var
gets compiled down to the correct type in the IL (you will see it about midway down article).按照 此链接(“C# 3.0 - Var 不是对象”),我看到var
被编译为 IL 中的正确类型(您将在文章中途看到它)。
My question is how much more, if any, IL code does using the var
keyword take, and would it be even close to having a measurable level on the performance of the code if it was used everywhere?我的问题是,如果有的话,IL 代码使用var
关键字的情况还有多少?
解决方案:
参考一: https://stackoom.com/question/1Upa参考二: Will using 'var' affect performance?