Why use dynamic typing in c#?

后端 未结 6 2254
旧时难觅i
旧时难觅i 2020-12-17 23:53

At first I thought something like:

var aName=getAllSomethings();

Is very unreadable, and so I\'ll use dynamic typing just when there\'s

6条回答
  •  不思量自难忘°
    2020-12-18 00:40

    Using the var keyword isn't dynamic typing. The var keyword is handled by the compiler. The variable gets statically typed based on the first assignment to the variable.

    The type of:

     var value = new StringBuilder();
    

    Is StringBuilder. There's no way to change that type (which is what dynamic typing would allow).

    What Jon Skeet is referring to in his blog is the dynamic keyword. That is a whole other beast.

提交回复
热议问题