声明变量和数据类型有什么区别

时间:2018-04-30 14:11:26

标签: c#

我目前正在创建一个软件应用程序,我想知道在声明变量时性能的速度是否存在差异。我目前正在使用这两种不同的方法。

这是我在声明变量时使用的第一种方法:

int productID, itemQuantity, cashAmount;

这是我在声明变量时使用的第二种方法:

int productID;
int itemQuantity;
int cashAmount;

我想知道在声明变量时使用的最佳方法是什么,第一种或第二种。

1 个答案:

答案 0 :(得分:9)

不,没有区别。

int productID, itemQuantity, cashAmount;

只是程序员的简写

int productID;
int itemQuantity;
int cashAmount;

并编译为完全相同的结果(IL代码):

.locals init ([0] int32 productID,
         [1] int32 itemQuantity,
         [2] int32 cashAmount)

(指数取决于是否有更多的局部变量)

相关问题