Why is C# statically typed?

前端 未结 17 2766
不思量自难忘°
不思量自难忘° 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:51

    One things that hasn't been mentioned is that C# is a CLS (Common Language Specification) compliant language. This is a set of rules that a .NET language has to adhere to in order to be interopable with other .NET languages.

    So really C# is just keeping to these rules. To quote this MSDN article:

    The CLS helps enhance and ensure language interoperability by defining a set of features that developers can rely on to be available in a wide variety of languages. The CLS also establishes requirements for CLS compliance; these help you determine whether your managed code conforms to the CLS and to what extent a given tool supports the development of managed code that uses CLS features.

    If your component uses only CLS features in the API that it exposes to other code (including derived classes), the component is guaranteed to be accessible from any programming language that supports the CLS. Components that adhere to the CLS rules and use only the features included in the CLS are said to be CLS-compliant components

    Part of the CLS is the CTS the Common Type System.

    If that's not enough acronyms for you then there's a tonne more in .NET such as CLI, ILasm/MSIL, CLR, BCL, FCL,

提交回复
热议问题