Difference between the implementation of var in Javascript and C#

后端 未结 5 779
情深已故
情深已故 2020-12-29 20:33

I would like to ask a theoretical question. If I have, for example, the following C# code in Page_load:

cars = new carsModel.carsEntities();

var mftQuery =          


        
5条回答
  •  没有蜡笔的小新
    2020-12-29 21:22

    a) C#'s var lets you avoid writing an explicit type upon variable declaration. This makes your code more compact, also sometimes the type of the expression on the right side of the declaration is complicated and in the same time you are not interested what the actual type is.

    b) Javascript's var is like C#'s dynamic. It lets you declare a variable but you can change its type.

    var i = 1; 
    i = "foo";  // legal in Javascript, illegal in C#
    

提交回复
热议问题