var keyword runtime or compile time?

前端 未结 3 487
闹比i
闹比i 2020-12-05 16:45

var keyword gets the type at the runtime or compile time?

or depends?

相关标签:
3条回答
  • 2020-12-05 17:02

    Plain and simple: compile time

    var isn't a type. The actual type is figured out at compile-time.

    var variables are also known as Implicitly Typed Local Variables (C# Programming Guide)

    0 讨论(0)
  • 2020-12-05 17:09

    var type gets at compile time .

    Var is an implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type

    var i = 10; // implicitly typed
    int i = 10; //explicitly typed
    

    http://msdn.microsoft.com/en-us/library/bb383973.aspx

    0 讨论(0)
  • 2020-12-05 17:10

    The var keyword is implicitly typed. This means that it is strongly typed, but the compiler determines the type.

    0 讨论(0)
提交回复
热议问题