1. Step by Step Learning C # (i):. NET architecture (knowledge points)

Source: Internet
Author: User
Tags visual studio 2010

A . C # and. NET Relationships

1. First, there are two important aspects of the C # language: First it is designed for the combination of Microsoft's. NET framework, and secondly it is a language for designing a problem-solving approach that has many of the strengths of similar languages.

C # itself is a language, it is not. NET part, both have their own strengths, but the two are used together.

2. What is . NET

. NET is Microsoft's next-generation technology platform, to build an interconnected application system for agile commerce, which is standard-based, connected, adaptable, stable and high-performance. NET application It is a run on. NET

Applications above the framework. (To be more precise, say one.) NET application is an application that is written using the. NET Framework class library and runs on the common language runtime Common Language runtime.

Two. Common language runtime

1. the core of the. NET Framework is the common language runtime (CLR) or the. NET runtime, which typically refers to code that runs under the CLR console as managed code (managed).

Two ways to complete compilation in. NET: 1 • Convert source code to Microsoft intermediate language. 2 · Use the CLR to compile IL into platform-specific code. The concept of the Microsoft intermediate Language: Low-level language, simple syntax, (the syntax is simply expressed in the use of digital code instead of text code), can be quickly converted to local machine code, for the code this design has an important bit: platform-independent, improve performance and language interoperability.

1>. Platform-agnostic: The same file that contains the bytecode directive can be placed in any platform, the compilation after the runtime can be done easily, so that the code running on the platform is specific, in other words, is compiled into an intermediate language at the same time obtained. NET platform-agnostic. And it is the same as it is when compiling Java bytecode will get Java platform independence.

2> improves performance: Because IL is always compiled on the Fly (JIT-compiled), the previous Java will convert bytecode into internal executable code when running the application, which can result in a loss of performance, and JIT compilation is a way of translating bytecode into machine code at run time, Techniques to improve the performance of bytecode compilation languages. The JIT compiler does not compile the whole program one at a time, so if you compile it all at once, you will waste a lot of it, but only compile the part that is called. Once the code is compiled, the resulting local executable is stored, knowing that the program is exited so that it does not have to be recompiled the next time the code is run.

3> Language interoperability: IL features: platform agnostic Support, language interoperability (can compile any one language into intermediate language) compiled into language code and other languages compiled code to interoperate with each other.

Three. Intermediate language

characteristics of the intermediate language: • Object-and interface-oriented support • Significant differences between value types and reference types • Strong data Typing • Use exceptions to handle errors • Use attributes (attribute).

Use. NET Framework provides a compiler that can directly compile the source program into an. exe or. dll file, but the program code compiled at this point is not a machine code that the CPU can execute directly, but
The code for the Intermediate language (IL).

Advantages of using the intermediate language: 1. Platform independence, which is independent of the specific CPU, can be achieved. 2. Just put. NET Framework to be compiled into IL code, the implementation of a language. The interaction between languages in the NET Framework.

1.COM interface concept: To provide a contract, the class that implements the given interface must provide an implementation of the methods and properties specified by the interface.

In addition, the intermediate language introduces the concept of interface

In addition, the intermediate language introduces the concept of the interface. NET establishes an interface different from the COM interface, and it does not support any COM infrastructure such as: they are not derived from IUnknown and do not have corresponding GUIDs, but they share the same philosophy as COM interfaces.

The meaning of language interoperability: A class written in one language should be able to communicate directly with classes written in another language. The main points are: 1. Classes written in one language should inherit classes written in another language. 2. A class should be able to contain an instance of another class, regardless of the language in which the two classes are used. 3. An object should be able to directly invoke methods that write another object in another language. 4. The application of the object should be able to be passed between methods. 5. When calling methods between different languages, you should be able to debug these method calls alternately in the debugger, that is, debugging source code written in different languages.

2. Different value types and reference types, his attributes are notable differences between value types and reference types. Storage methods: Value types, variables store their data directly, and for reference types, the variable stores only its address, and the corresponding data can be found in the address.

Strong data Typing
If the data type is not explicitly converted, it cannot be arbitrarily assigned, called a strong data type. Relative weak data type, in the case of non-display conversion, it is assigned to other types, can do automatic conversion, called weak data type. An important aspect of the above intermediate language is that it is based on strong data typing. Forcing the implementation of type security can degrade performance. But in many cases, we are from. NET provides more benefits in a service that relies on type safety. Services include: • Interoperability of languages • Garbage collection • Security • application domains.
1. The important reason for strong data typing in language interoperability: If a class derives from another class or contains an instance of another class, it needs to know all the data types used by other classes.
For example, suppose a method in a Visual Basic 2010 class is defined to return an integer---One of the standard data types that Visual Basic 2010 can use. But C # does not have a data type of that name, and it is clear that only the compiler knows how to map the integer type of Visual Basic 2010 to a known type defined by C #, which can be derived from that type, use this method, and use the returned type in C # code, which is the problem. NET how to solve it?
Answer: This type of data problem is in the. NET is addressed by using the type System (CTS). The integer of Visual Basic 2010 is actually a 32-bit signed integer that is actually mapped to the intermediate language type Int32, so specifying this type of data in the intermediate language code, which the C # compiler can use, solves the problem.

The hierarchical structure of the CTS reflects an object-oriented approach to the single inheritance of intermediate languages.


garbage collection , used in. NET for memory management, especially it can recover the memory that is needed to recover the applications that are running.

The Windows platform has used two techniques to free up the memory that the process is requesting dynamically from the system: 1 • Fully manual application code to complete these tasks. 2 · Let the object maintain the reference count. So. NET runtime is a garbage collector, which is a program that is designed to clean up memory. When using the method, all dynamically requested memory is allocated to the push (all languages are handled this way, but in the. NET, the CLR maintains its own managed heap for use by. NET applications). Every once in a while, when. NET detects that the managed heap for a given process is full, the garbage collector is called when it needs to be cleaned. The garbage collector processes all variables in the current code, detects references to objects stored on the managed heap, determines which objects can be accessed from code, which objects have references, and objects that are not referenced are not considered accessible from the code and thus are deleted.

application Domains It is used to reduce the overhead of running applications that need to be detached from other programs, but still need to communicate with each other.

The only way to isolate code is through a process, when a new application is launched, it runs within a process environment, Windows separates the process from the address space, each process has 4GB of virtual memory to store its data and executable code, (4GB corresponds to a 32-bit system) it uses an additional indirect way to mount these virtual memory to a particular area of physical memory or disk space, each of which has different mounts, and the virtual address space blocks mount physical memory without overlapping.

Any process can access memory only by specifying an address in virtual memory, which means that the process cannot access physical memory directly, so one process cannot access the memory allocated to another process.

Processes help to ensure security, but they have a big drawback is performance. The solution to this problem is to use a DLL-based component to have all components run in the same address space ———— the risk is that the component that performs the error affects the other components.

An application domain is a way of detaching components that do not cause performance problems by passing data between processes, by decomposing any one process into multiple application domains, one for each application, and each running in a specific application domain.

Assembly

An assembly is a logical unit that contains compiled, code that targets. NET framwork.

Important: It is a logical unit. An important feature of assemblies is that they contain metadata that describes the types and methods defined in the corresponding code, and the assembly contains the program's metadata.

There are two types of assemblies: private assemblies and shared assemblies. 1. Private assemblies are typically attached to a software, and it is common to provide applications in the form of executables or many libraries that contain code that can only be used for that application. 0 Impact (xcopy) installation is to place the corresponding file in the corresponding folder in the file system. Shared assemblies are common libraries that other applications can use. The global assembly cache places a shared assembly in a specific subdirectory tree of the file system. Assigning a name to a shared assembly according to private key cryptography is called the strong name. (Must be referenced by the application that is referencing the shared assembly).

Reflection This metadata can be accessed programmatically because the assembly stores metadata, including all types defined in the program and the details of the members of those types.

. NET base class is very intuitive and easy to use. For example, to start a thread, you can call the start () method of the thread class. To disable textbox, set the Enabled property of the TextBox object to False.

Namespaces can be nested with each other, most for general purposes. NET base class is located in the namespace system, the base class Arry in this namespace, and the full name is System.arry. NET needs to define all the types in the namespace such as: Put the Customer class in the namespace Yourcompanyname, then the full name of this class is Yourcompanyname.customer.

Created in C #. NET application

The ability to create ASP. 1.asp.net Application

Main Asp. NET page is structured, ASP. NET page is another advantage of being able to build them in Visual Studio 2010, where you can create the business logic and data access components that are used by the ASP. Wed server controls are used to add controls to an wed form and ActiveX controls are not a control, they are XML tags in the ASP. Net Namespace.

XAML is the XML declaration used to create a form that represents all the visual parts and actions of a WPF application.

. NET has the following features in the compilation and execution process: assemblies and. NET base classes, COM components, JIT compilation, application domains, garbage collection.

1. Step by Step Learning C # (i):. NET architecture (knowledge points)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.