Is there any technical reason to use or not to use var in C# when the type is known?

后端 未结 8 2124
南方客
南方客 2021-01-02 04:05

It seems that more and more C# code I read uses the var type identifier:

foreach (var itemChange in ItemChanges)
{
   //... 
}
8条回答
  •  醉酒成梦
    2021-01-02 04:08

    var is a C# 3.x+ feature, isn't it? without using that, your code is more compatible with other versions too.

    And there is lots of interesting questions in SO, when you search "var C#"

提交回复
热议问题