Why is C# statically typed?

前端 未结 17 2923
不思量自难忘°
不思量自难忘° 2020-12-01 05:07

I am a PHP web programmer who is trying to learn C#.

I would like to know why C# requires me to specify the data type when creating a variable.

Class         


        
17条回答
  •  心在旅途
    2020-12-01 05:56

    In C# 3.0, you can use the 'var' keyword - this uses static type inference to work out what the type of the variable is at compile time

    var foo = new ClassName();
    

    variable 'foo' will be of type 'ClassName' from then on.

提交回复
热议问题