Why would var be a bad thing?

前端 未结 17 1912
误落风尘
误落风尘 2020-12-04 17:21

I\'ve been chatting with my colleagues the other day and heard that their coding standard explicitly forbids them to use the var keyword in C#. They had no idea

17条回答
  •  不思量自难忘°
    2020-12-04 18:15

    var q = GetQValue();
    

    is indeed a bad thing. However,

    var persistenceManager = ServiceLocator.Resolve();
    

    is perfectly fine to me.

    The bottomline is: use descriptive identifier names and you'll get along just fine.

    As a sidenote: I wonder how do they deal with anonymous types when not allowed to use var keyword. Or they don't use them altogether?

提交回复
热议问题