C# Advanced Programming (1)-.NET Architecture

黄舟
Release: 2017-03-20 11:15:26
Original
1293 people have browsed it

1.1 C#Relationship with .NET

C# cannot be used in isolation and must be used together with the .NET Framework.

    (1)C#’s architecture and methodology reflect the .NET basic methodology.

    (2) In most cases, C#'s specific language features depend on .NET features, or rely on .NET base classes.

Some features supported by .NET are not supported by C#. There are other features supported by the C# language that are not supported by .NET.

1.2 Common Language Runtime (CLR)

 1.2.1 Platform independence

The core of the .NET Framework is its runtime environment, called the common language runtime (CLR) or .NET runtime.

Code that runs under the control of the CLR is usually called managed code.

How .NET compiles code:

Stage 1: Compile the source code into Microsoft Intermediate Language (IL).

    *IL is similar to the bytecode in JAVA.

Stage 2: The CLR compiles IL into platform-specific code.

1.2.2 Improve performance

The JIT (just-in-time compiler) compiles the application when it is running, so the JIL knows exactly Depending on what type of processor the program runs on, it can be optimized for that processor to improve performance.

 1.2.3 Language interoperability

  Visual Basic 2013, Visual C++ 2013, Visual F#, COM and COM+, Windows runtime library.

1.3 Intermediate Language

The main features of the intermediate language:


    • IL generally does not allow any operations on ambiguous data types, although forcing type safety seems to reduce performance, but in most cases Below we get more benefits from the services provided by .NET that rely on type safety. These services include:

    • Language interoperability

    • Value type (value type), variables store their data directly, intermediate language is stored on the stack (if declared as fields in a reference type, they are stored inline pile).

    • Reference type (reference type), variables only store addresses, and instances of reference types are always stored in a memory area called the "managed heap".

    • Forced typing

    • The true meaning of language interoperability Using a language Classes should be written to communicate directly with classes written in another language. Such a tool is provided (by the Visual Studio IDE) (not the CLR).

    •  Object-orientedand using interface

    • Value types and Significant differences between reference types.

The importance of strong data typing in language interoperability

If a class derives from or contains instances of other classes, it needs to know all the data types used by other classes, which is why language interoperability is very important.

Solutions in .NET



    • ##Common Type System (CTS)



# CTS defines predefined data that can be used in the intermediate language Types, all languages ​​targeting the .NET Framework can generate compiled code that is ultimately based on these types.

CTS also allows you to define your own types of code.

The hierarchical structure of CTS reflects the singleness of the intermediate language

inherits the object-oriented approach of .


    • ##Common Language Specification (CLS)

    • # It is acceptable to write non-CLS code, but by doing so we cannot guarantee that it will compile IL code fully supports language interoperability.

    Garbage Collection
    • Security
    • Application Domain
    • The garbage collector is used for memory management in .NET, especially It can restore the memory needed by running applications.
    • # Check the managed heap for unreferenced objects and delete them.
    • Use exceptions to handle errors
    • Use attributes

The above is the detailed content of C# Advanced Programming (1)-.NET Architecture. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!