A good entry C # Getting Started tutorial

Source: Internet
Author: User
I know little about Java, but the fully object-oriented technology makes development easier, which is beyond doubt .. NET development. Recently, I found it easier to use. Net to develop the interface, so I took a deep look at C # learning. Of course, to use. NET and Visual C #, you must first learn the C # language. Thanks to this book, I quickly completed the transition from C ++ to C. The other part is "C # Language Reference", which is a manual and does not need to be fully read. It is mainly a reference. I have asked why I don't use C ++. net has both C ++ syntax and. net syntax language, I said, that thing is to make C ++ complex to implement. net, while C # implements C ++ simply. net, So C ++. net is twice more difficult to learn than C. 2. I firmly support C ++ and APIs, because this is still the most basic. In particular, I think C ++ has a lot of expertise in implementing some algorithm techniques. Thank you.


Preface

0.1 Summary

Read presenting C #). This book is a shortcut for you to improve your enterprise programming language. This enterprise programming language comes with the next-generation programming language service runtime (ngws runtime): C # (pronounced "C sharp ").

Ngws Runtime is a dynamic environment that not only manages Execution Code, but also makes programming easier. The compiler generates managed code to point to this Managed execution environment. You get cross-platform language integration, cross-platform language Exception Handling, enhanced security, version control, arrangement support, and error detection services.

C # is the main language that supports ngws runtime #. Many programs that support the ngws framework are written in C #. Therefore, in some compilers with ngws runtime, their compilers can be considered to be highly tested and optimized. C # Language draws on C ++, but it has modern and new types of security-making C # The preferred language for enterprise solutions.

0.2 who should read this book

This book is not suitable for you if you are unfamiliar with programming. This book attempts to free programmers from using C # based on their existing knowledge. The purpose of "show C #" is to target programmers who already have experience in programming such as C/C ++, VB, Java or other programming.

If you have a C ++ background, it will be easy to switch to C #. However, if you are proficient in other languages, this book will also consume some of your days. If you have a little knowledge about COM programming, this will be more interesting, but it will be no longer necessary for COM programming.

How to organize this book 0.3

Chapter 1 C # introduction -- This chapter takes you to C # for a stroll and answers questions about how to consider learning C.
Chapter 2 ngws runtime technical basis-introduces the Low-layer architecture provided by ngws runtime for running C # code.
Chapter 3 first C # Application -- create the first C # application (otherwise, what is it ?), It is a "hello World" application.
Chapter 4 C # type -- you can see various types used in the C # application. Explore the differences between the value type and the reference type, as well as how to add and remove boxes.
Chapter 5 Class C # is a sign of true power. It is class-oriented object-oriented programming. You will learn a lot of things, such as constructors, destructor, methods, attributes, indexes, and events.
Chapter 6 control statements-Implement Process Control for applications. Explore the various options and statement provided by C.
Chapter 7 Exception Handling-get the application skills for compiling and implementing Exception Handling. With this skill, you are a good citizen in the ngws runtime world.
Chapter 8 use C # To write components -- use C # To build components. Because ngws Runtime is supported, it can be used by customers of different language platforms.
Chapter 9 configuration and arrangement-learn how to use C # Conditional compilation and how to automatically create documents for your C # source code. In addition, this chapter introduces the ngws version technical issues.
Chapter 10 interaction with unmanaged code -- discover how you use the unmanaged code in C # And how the unmanaged code interacts with your C # component.
Chapter C # code error checking-get the skills to use the SDK error checking tool to accurately locate and modify errors in the application.
Chapter 2 Security: exploring the concept of ngws runtime security. Learn about code access security and role-based security.

0.4 what do you need to use this book?

From the perspective of this book, all you need is the next-generation Windows service software development kit (ngws SDK ). Although at least ngws runtime and C # compilers are available, when exploring these exciting new features, installing instruction files and all SDK tools (including debugger) on a machine is an excellent idea.
This book does not require any tools installed on your machine in Visual Studio 7. I only recommend that you have an excellent program editor that supports the number of lines to edit the C # source file.
......
(Omit some paragraphs related to the publishing process and express gratitude)

0.5 about the author

Christoph Wille, Microsoft System Engineer (MCSE), Microsoft system developer (MCSD), Netware Network Administrator (CNA) and MCP-IT, as a network consultant and programmer, especially proficient in Windows DNA. Microsoft regards him as the most valuable person (MVP) in ASP, and he is one of the few developers who used the early C # version with Microsoft.
Christoph has written several books independently or independently, including SAMs press's "21 days of self-study ado2.5", "24 hours of self-study asp", "14 days of self-study MCSE TCP/IP", and "MCSE Training Guide: SQL Server 7 Management".

Chapter 1 C # Introduction  

Welcome to the world of C! This chapter introduces you to the world of C # And answers some related questions, for example, why do you have to use C #, C ++, and C, and why C # makes development easier and interesting.

Why is it another programming language?
One question that must be answered: When you have used C ++ or VB for enterprise development, why should you learn another language? The market answer is: "in the enterprise computing field, C # will become the main language for compiling" Next Generation Windows Services "(ngws) applications. "This Chapter provides support for parameter requests and displays some functions of C. This chapter will make you appetizing.

C # Language evolved from C/C ++. However, it is modern, simple, fully object-oriented, and type-safe. If you are a C/C ++ programmer, the learning curve will be smooth. Many C # statements use your favorite language, including expressions and operators. If you do not look at it carefully, you will simply regard it as C ++.

The most important thing about C # is that it is a modern programming language. It simplifies and modernized C ++ in fields such as class, namespace, method overload, and exception handling. The screen discards the complexity of C ++, making it easier to use and less error-prone.

Which contributes to the ease of use of C # is to reduce some features of C ++, without macros, templates, and multi-inheritance. Especially for enterprise developers, the above functions will only produce more troubles than benefits. New features that make programming more convenient are strict type security, version control, and garbage collect. All these functions aim at developing component-oriented software.

Before continuing to present more features, I would like to stop and explain the various essential elements of C # below.

Simple
Modern
Object-oriented
Type Security
Version Control
Compatible
Flexible

Simple

C # One advantage that C ++ does not possess is that it is easy to learn. The primary goal of this language is simplicity. Many functions (not to mention the lack of some functions of C ++) Help C # complete simplicity.

In C #, no pointers are popular in C ++. By default, you work in managed code, where insecure operations such as direct access to memory are not allowed. I think no C ++ programmer can claim that they have never used pointers to access their memory.

What is closely related to the pointer "dramatic" is the "stupid" operation. In C ++, operators such as:,., and-> are used for namespaces, members, and references. For beginners, operators are still difficult to learn. C # discard other operators and only use a single operator ".". What a programmer needs to understand now is the annotation of nested names.

You do not have to remember the implicit types based on different processor architectures, or even the ranges of various integer types. C # using a unified type system, the C ++ variable type system is discarded. This system allows you to view various types as an object, whether it is an original type or a full-blown class. Compared with other programming languages, the mechanism of boxing and unboxing does not improve the performance of processing simple types as objects. I will explain in detail box adding and box removing later, but basically only use the simple type of object access technology when needed.

First, sophisticated programmers may not like it, but integer and Boolean types are now two completely different data types. This means that the wrong value assignment in the original if statement will be compiled incorrectly, because the if statement only accepts boolean values. There will no longer be errors such as misuse of the value assignment operator as a comparison character! (After learning C # For the first time, cnbruce realized that "=" and "= ":)

C # also solves the redundant things that have existed in C ++ for some years (redundancies ). This type of redundancy includes constant pre-Definition and different character types. Since redundant forms have been removed from the language, forms can be used in C.

 


 

Modern

Your effort to study C # is a big investment, because C # is designed to write the main language of the ngws application. You will find that many functions that can be implemented or implemented with C ++ are just some basic functions in C.

For enterprise-level programming languages, new financial data types are very popular. You use a new decimal data type, which is used for financial computing. If you do not like this easy-to-use type, you can easily create a new data type based on your application's special needs.

As I have mentioned, pointers are no longer part of your programming weapon. Don't be surprised. Full memory management is no longer your task. At runtime, ngws provides a garbage collector responsible for memory management in the C # program. Because both the memory and applications are managed, it is necessary to enhance type security to ensure application stability.

For C ++ programmers, exception handling is not new, but it is the main function of C. The difference between C # Exception Handling and C ++ is that it is a cross-language (another function at runtime ). Before C # is available, you must handle weird hresults, but now it's all over because of the exception-based robust error handling.

For modern applications, security is the top priority, and C # is no exception. It provides metadata syntax to declare the capabilities and permissions of the following ngws security mode. Metadata is a key concept for running ngws. The next chapter will introduce its deeper meaning.

Object-oriented

You don't expect that a new language does not support object-oriented functions, right? C # certainly supports all key object-oriented concepts, such as encapsulation, inheritance, and polymorphism. The complete C # class mode is built on the upper layer of the Virtual Object System (VOS) When ngws is running. Vos is described in the following chapter. The object mode is only a basic part and is no longer part of the programming language.

The first thing you must pay attention to is that there are no global functions, variables, or constants. All things are encapsulated in the class, including case members (accessible through the class case-object) or all static members (through the data type ). These make C # code easier to read and help reduce potential naming conflicts.

The methods in the definition class are non-virtual by default (they cannot be rewritten by the derived class ). The main argument is that this will eliminate other original code errors caused by occasional method rewriting. To rewrite the method, you must have an explicit virtual flag. This behavior not only slows down the virtual function table, but also ensures correct version control.

Using C ++ to write classes, you can use access modifiers to set different access levels for class members. C # supports three access permissions: private, protected, and public, and adds the fourth type: internal. Details about access permissions are described in Chapter 5 "class.

How many classes have you created are derived from multiple base classes (ATL programmer, your vote is not counted !) ? In most cases, you only need to derive from a class. Multi-base classes usually cause more trouble than they solve. That is why C # only allows one base class. If you think you need multiple inheritance, you can use the interface.

A possible problem: a pointer does not exist in C #. How can we imitate it? The answer to this question is representative. It provides support for the ngws running current event mode. Again, I will put the full explanation of it in chapter 5.

Type Security

I select a pointer again as an example. With a pointer in C ++, You can freely convert it to any type, including producing a pointer such as an int * (integer pointer) forced conversion into a double * (Double Precision pointer. As long as the memory supports this operation, it is "dry ". This is not the type security you think of as an enterprise-level programming language.

Outline the problem, C # implements the strictest type of security to protect yourself and the garbage collector ). Therefore, you must follow the rules of some related variables in C:

You cannot use a variable without initialization. The compiler is responsible for clearing member variables of objects. You are responsible for resetting local variables. When you use a variable without initialization, the compiler will teach you how to do it. The advantage is to avoid errors caused by the calculation results of uninitialized variables, and you do not know how these strange results are produced.

C # The unsafe type conversion is canceled. You cannot forcibly convert an integer into a reference type (such as an object). When downconversion is performed, C # verifies that the conversion is correct. (That is, the derived class is actually derived from the class that is converted down .)

Border Check is part of C. This will never happen again: When the array actually only defines n-1 elements, n elements are used in excess.

Arithmetic Operations may overflow the range of the final value data type. C # allows you to detect these operations at the statement or application level. When overflow detection is allowed, an exception is thrown when overflow occurs.

In C #, the passed reference parameters are type-safe.

Versionable)

In the past few years, almost all programmers have to deal with the well-known "DLL hell" at least once ". This problem occurs when multiple applications have different versions with the same DLL name installed. Sometimes, older versions of applications can work well with new versions of DLL, but more often they interrupt the operation. The current version issue is really a headache.

As you will see in Chapter 8 "Write components in C #", ngws runtime provides version support for your applications. C # It is best to support version control. Although C # cannot ensure correct version control, it is possible for programmers to ensure version control. With this support, a developer can ensure that the binary compatibility with existing customer applications is retained when the class library is upgraded.

Compatible

C # does not exist in a closed world. It allows access to different APIs using the most advanced ngws Common Language Specification (CLS. CLS specifies a standard for internal operations in a language that complies with this standard. To enhance CLS compilation, the C # compiler detects all public exit compilation and lists errors when they are out of date.

Of course, you also want to access the old COM object. Ngws provides transparent access to com during runtime. How to integrate the original code is described in Chapter 10th "internal operations on non-managed code.

OLE Automation is a special animal. Anyone who creates an OLE automation project using C ++ already enjoys various types of automated data. The good news is that C # supports them without the hassle of locking details.

Finally, C # allows you to use the C-prototype API to perform internal operations. You can access any DLL entry point (with a C prototype) from your application ). The function used to access the original API is called the platform call service (pinovke). Chapter 10th describes some examples of using the c api for internal operations.

Flexible

The last section of the previous section may remind programmers. You may ask, "Isn't there an API for passing pointers? "You are correct. There are not only a few such APIs, but many (somewhat conservative estimates ). This access to the original Win32 code sometimes leads to the use of the specified pointer for the unsafe class (although some of them can be solved by the support of COM and pinvoke ).

Although the default status of C # code is type-safe, you can declare some classes or declare methods of only classes as non-secure types. Such a statement allows you to use pointers and structures to statically allocate arrays. Both the security code and the non-security code run in the same management space, which implies that when the non-security code is called from the security code, it will not fall into the column set ).

Summary

C # Language evolved from C and C ++. It was created for enterprise developers who are willing to sacrifice C ++'s underlying functions for convenience and productization. C # Modern, simple, object-oriented, and type security. Although it draws on many things of C and C ++, there are still huge differences between them in some specific fields such as namespace, classes, methods and exception handling.

C # provides you with convenient functions, such as garbage collection, type security, version control, and so on. The only "price" is that the Code operation is type-safe by default, and pointer is not allowed. Type security alone is enough. However, if you need pointers, you can still use them using non-secure codes. When you call non-secure codes, they cannot contain column sets.

 


Chapter 2 theoretical basis-Public Language Runtime Environment

Now that you are fully impressed by C #, I want to give you a full picture of ngws runtime. C # depends on the runtime provided by ngws. Therefore, it is necessary to know how the runtime works and the concepts behind it.
Therefore, this chapter is divided into two parts-they are the basis of all concepts and usage. Although the two parts overlap, they help to deepen understanding of the concepts being learned.

2.1 ngws Runtime

Ngws and ngws runtime provide you with a runtime environment. This runtime manages the Execution Code and provides services that make programming easier. As long as your compiler supports this runtime, you will benefit from this Managed execution environment.

You can guess that the C # compiler supports ngws runtime correctly, but not only does it support ngws runtime, but it also supports VB and C ++. These codes created to support runtime are called managed code ). The following are the benefits your application has gained from ngws runtime:

Cross-language integration (using general language specifications)
Automatic Memory Management (garbage collection)
Cross-language Exception Handling (uniform expansion)
Enhanced security (including type security)
Version support ("DLL hell" Terminator)
Simplified component Interaction Mode

Because ngws runtime must provide all these benefits, the compiler must issue the Metafile along with the managed code. The metadata file describes the type in the code. It exists with your code (similar to PE-PE is a variable-bit execution file)

As you can see from many cross-language functions, ngws Runtime is mainly about tight integration into SS multiple different programming into ages ). This kind of support allows you to derive a C # class from a VB object (I will discuss it later ).

C # A feature programmers will like is that they don't have to worry about memory management-that is, they don't have to worry about notorious memory leaks. Ngws runtime provides memory management. When the life cycle of objects and variables ends (no longer referenced), the garbage collector releases them. I really like this feature, because memory management in COM has always been a heart disease for me.

You should be encouraged to configure a management application or component. Because the management application contains metadata files, ngws runtime can use this information to ensure that your application has various required versions. The obvious result is that your code is rarely interrupted because it does not depend on each other.

The remainder of this chapter is divided into two parts, each of which discusses various aspects of ngws runtime until your C # application can be executed.
1. Intermediate Language (IL) and metadata
2. Instant Compiler (just-in-time compliers)

2.1.1 intermediate language and metadata

The managed code generated by the C # compiler is not the original code, but it is the intermediate language (IL) code. This Il Code itself becomes the entrance of the ngws runtime Managed execution process. The obvious advantage of IL code is that it is CPU-independent, which means that you must use a compiler on the target machine to convert the Il code into the original code.

Although the Il code is generated by the compiler, it is not the only thing the compiler provides to the runtime. The compiler also generates metadata about your code, which tells the runtime more about your code, such as definitions of various types, signatures of various types of members, and other data. Basically, metadata is the type library, registry content, and other information used for com. Even so, metadata is directly merged with the Execution Code and is not isolated.
Iland metadata are stored in files that extend the pegex format (the pegex is used in .exe and. DLL files ). When such a PE file is loaded, metadata and Il are located and separated from the file during the runtime.

Before proceeding, I would like to give you a short directory of the existing il commands. Although it is not a complete list and you do not need to memorize and understand it, it lists the knowledge base you need for the C # program.

Arithmetic and logical operators
Control Flow
Direct Memory Access
Stack operations
Parameters and local variables
Stack allocation
Object Mode
Instance type value
Critical Section
Array
Classification position
Instant Compiler (jitters)

 


 

2.1.2 instant Compiler (jitters)

The managed code generated by C # or other compilers that can generate the managed code is the Il code. Although the Il code is encapsulated in a valid PE file, you still cannot execute it unless it is converted into the managed original code. This is the time when the ngws runtime instant Compiler (also known as jitters) is amazing.
Why are you tired of compiling code in real time? Why don't you compile the entire il PE file into the original code? The answer is time-the time when the Il code needs to be compiled into the CPU specification code. This compilation will be more efficient, because some program segments have never been executed. For example, in my word processor, the Mail Merge function has never been compiled.

Technically, the entire process is as follows: when a type is loaded, the loader creates a stub and connects it to each type of method. When a method is called for the first time, the stub gives the control to JIT. JIT compiles Il as the original code and points the pointer to the buffered original code. The subsequent call will execute the original code. At some point, all the Il is converted into the original code, and the jitter is idle.

As I mentioned earlier, there are many JIT compilers. On Windows, ngws runtime has three different JIT compilers.

JIT -- this is the default JIT compiler used by ngws runtime. It is a back-end optimized compiler that performs Data Flow Analysis on the frontend (up front) and creates a highly optimized and managed original code for output. JIT can use less rigorous il instruction set encoding, but the required resources will be considerable. The main limits are the memory footprint, the result working set, and the time consumed by optimization.

Economy jit -- compared with the main JIT, econjit aims to convert il into the managed original code at high speed. It allows buffering of the original code, but the output code is not as optimized as the code generated by the main JIT (the code is small ). When the memory is insufficient, the advantages of the quick code generation solution will disappear. By permanently throwing away useless JIT code, you can mount a larger il program into the code buffer. Because JIT compilation is fast, the execution speed is still fast.

Prejit-although it is based on the main JIT, it operates more like a unified compiler. After you install the ngws component, you can run it to compile the Il code into the managed original code. Of course, the final result is faster loading time and faster application startup time (no more JIT compilation is required ).

In the listed jitters, there are two jitters at runtime. But how do you decide which JIT to use and how to use the memory? There is a small application (jitman.exe) called "JIT compilation manager", which is stored in the bin directory under the ngws SDK installation directory.

Although it is a small dialog box, the options you select are quite powerful. Each option is described below.

Use Economy JIT only option -- if this check box is not selected, ngws runtime uses the default normal JIT compiler. I have explained the differences between the two jitter types.

Max code pitch overhead (%) option -- this setting is reserved only for the economy JIT. It controls the JIT compilation time and the percentage of code execution time. If the value of the specified domain is exceeded, the Code buffer is expanded to shorten the time consumed by JIT compilation.

Limit size of code cache option -- this option is not selected by default. If this option is not selected, the buffer will use the memory it can obtain. If you want to limit the buffer size, check this option, which allows you to use the max size of cache (bytes) option.

Max size of cache (bytes) Option-controls the maximum value of the buffer that holds JIT code. Although you can strictly limit this value, you should be careful not to exceed the maximum value suitable for this buffer zone. Otherwise, the JIT compilation of this method will fail.

Optimize for Size Option-tells the JIT compiler that the optimization is intended to make the code smaller than to execute faster. This setting is disabled by default.

Enable concurrent GC [Garbage Collection] Option -- garbage collection (GC) runs in the user code thread by default. This means that when GC occurs, you may notice a slight latency in the response. To prevent this problem, open the current GC. Note: The current GC is slower than the standard GC. It is only valid when writing on Windows 2000 (the time of writing.

When using C # To create a project, you may have tried it using different settings. When creating a UI-intensive application, you will see the maximum difference that allows the current GC.

2.2 Virtual Object System (VOS)

So far, you have only seen how ngws runtime works, but you do not know the technical background of ngws and why it works like this. This section describes the ngws Virtual Object System (VOS ).

The following are the ngws runtime rules when a type model is declared, used, and managed in Vos. The idea behind vos is to build a framework that does not sacrifice performance when executing code, allowing cross-language integration and type security.

The framework I mentioned is the basis of the runtime architecture. To help you better understand it, I hooked it out of four areas. It is important to understand C # applications and components.

Vos type system-provides a wide range of type systems, which are intended to support full implementation of comprehensive programming languages.
Metadata-describes and references the types defined by the VOS type system. The permanent format of metadata is irrelevant to the programming language. However, metadata is used as an nterchange mechanism, which is between the virtual execution system of the tool and ngws.

 


 

General language specification (CLS)-CLS defines a subset of types in Vos, and also defines general usage. If a class library complies with the CLS rules, it ensures that the class library can be used in all other programming languages that can implement Cls.

Virtual Execution System (VES)-This is a real-time implementation of Vos. VES is responsible for loading and executing the program compiled when ngws is run.

These four parts constitute the ngws runtime architecture. Each part is described in the following section.

2.2.1 VOS

Vos provides a wide range of types, which are intended to support full implementation in multiple programming languages. Therefore, Vos must support both object-oriented and procedural programming languages.

Currently, there are many similar but somewhat incompatible types. Take an integer as an example. In VB, it is 16 bits long, and in C ++, It is 32 bits. There are more examples, especially data types used in date and time and databases. This incompatibility makes application creation and maintenance unnecessary, especially when the program uses multiple programming languages.

Another problem is that, because there are some differences between programming languages, you cannot reuse the types created in another language. (COM partially solved this problem using the binary standard interface ). Today's code reuse must be limited.

The biggest obstacle to publishing applications is the inconsistent object models of various programming languages. There are differences in almost every aspect: events, attributes, permanent persistence, and so on.

Vos will change this phenomenon. Vos defines the type of the description value and specifies a contract that must be supported by all values of the type. As we mentioned above support object-oriented and procedural programming languages, there are two types of values and objects.

For values, the type is stored in the representation statement, and the same operation is also performed in it. Objects are more powerful because they are explicitly stored in representations. Each object has a identification number different from other objects. Different vos types are supported in Chapter 4 "C # type.

2.2.2 metadata

Although metadata is used to describe and reference A type defined by a vos type system, it cannot be locked to this single target. When you write a program, the declared types (assuming they are numerical or reference types) are introduced to the ngws runtime type system by using the type declaration. The type declaration is described in the metadata stored in the PE executable file.

Basically, metadata is used for various tasks: used to indicate the information used by ngws runtime, such as locating and loading classes, examples of these classes in memory, solving calls, translating Il as the original code, enhancing security, and setting runtime context boundaries.

You don't have to worry about metadata generation. Metadata is generated by C #'s "code-to-il compiler" (not JIT compiler. The Code-to-il compiler sends binary metadata information to PE files in a standard manner. Unlike the C ++ compiler, it creates their own modifier names for exit functions.

The main advantage you get from the coexistence of metadata and executable code is that the information about types is fixed together with the same type and will not spread across many places. It also helps solve the version problems in COM. Further, you can use different version libraries in the same context, because the libraries are not only referenced by the Registry, but also referenced by metadata contained in executable code.

 


 

2.2.3 general language specifications

The general language specification (CLS) is not a real part of the Virtual Object System (VOS). It is special. CLS defines a type subset in Vos, and also defines that it must comply with conventional CLS usage.

So what are the puzzles about this? If a class library complies with CLS rules and other programming languages also comply with CLS rules, customers of other programming languages can also use class libraries. CLS is about interoperability ). Therefore, the general usage must only follow externally accessible projects (externally visible items) such as methods, properties, and events.

The advantage I have described is that you can do the following. Write a component in C # and derive it in VB. Because the function added to VB is so powerful, it is derived from the VB class again in C. This is feasible as long as all external accessible items comply with CLS rules.
The code I presented in this book does not care about CLS agreements. But when building your class library, you must note the CLS protocol. I provide Table 2.1 to define Protocol rules for types and externally accessible items.

This list is incomplete. It only contains some important projects. I don't point out every type of CLS protocol in this book, so there is a good idea: when looking for a CLS protocol, you should at least browse the table to see which function works. Don't worry that you are not familiar with every meaning in this chapter. You will learn them in this book.

Table 2.1 types and functions of the enable language specification

Bool
Char
Byte
Short
Int
Long
Float
Double
String
Object (mother of all objects)
Arrays (array)

The dimension of the array must be known (> = 1), and the minimum number of subscripts must be 0.
The element type must be a CLS type.

Type (types)

Can be abstracted or hidden.
Zero or more interfaces can be implemented. Different interfaces allow methods with the same name and signature.
A type can be accurately derived from a type. Allow Members to be overwritten and hidden.
There can be zero or more members, which are fields (fields), methods, events, or types.
Type can have zero or more constructors.
A type of accessibility can be public or partial to the ngws component. However, only public members can be considered as part of a type interface.
All value types must inherit from the system value type. An exception is an enumeration. It must be inherited from the system enumeration (system Enum.

Type Member

Type members can hide or overwrite other members of another type.
The type of parameters and returned values must be CLS protocol type.
Constructors, methods, and attributes can be overloaded.
A type can have abstract members, but only when the type is not encapsulated.

Method

One method can be static, virtual, or instance.
Virtual and instance methods can be abstract or an implementation. Static methods must always have an implementation.
The virtual method may be the last (or not ).

Field (fields)

It can be static or non-static.
Static fields can be described or initialized only.

Attribute

Attributes can be made public when obtaining and setting methods instead of using the attribute syntax.
The first parameter of the returned type and the setting method must be of the same CLS type-attribute type.
Attribute names must be different, and different attribute types are insufficient for differentiation.
Because the method is used to implement attribute access, if propertyname is an attribute defined in the same class, you cannot implement the methods named get_propertyname and set_propertyname.
Attributes can be indexed.
Attribute access must follow this naming format: get_proname, set_propname.

Enumerations)

The type must be byte, short, Int, or long.
Each member is a static description field of the enumeration type.
One enumeration cannot implement any interfaces.
You can set the same value for multiple fields.
An enumeration must inherit the system enumeration (hidden in C)

Exception

Can be triggered and captured.
Custom exceptions must inherit system exceptions.

Interface

You can implement other interfaces.
An interface can define attributes, events, and virtual methods. The implementation depends on the derived class.

Event

Either the Add or cancel methods are provided or none. Each method uses a parameter, which is a class derived from the system representative metadata.

Custom Attributes

Only the following types can be used: type, Char, Char, bool, byte, short, Int, long, float, double, Enum (a cls type ), and object.

Delegates)

Can be created and activated

Identifiers)

The first letter of an identifier must come from a restricted set.
It is impossible to uniquely distinguish two or more identifiers (Case Insensitive) within a single range by Case sensitivity ).

 


 

2.2.4 virtual execution system (VES)

The virtual execution system implements the virtual object system. Create ves by implementing an execution engine (EE) responsible for ngws runtime. This execution engine executes the applications you write and compile in C.

The following components are part of ves.
1. Intermediate Language (IL)-is designed to be easily compatible with various compilers. In addition to this framework, the C ++, VB, and C # compilers can generate Il.
2. Load the managed code-this includes the names in the memory, laying out classes, and creating the necessary stubs for JIT compilation. By performing regular verification, including enhancing some access rules, the Class Loader also enhances security.
3. Using JIT to convert the Il code into the original code-the Il code is not designed as a traditional interpretation of byte code or tree code, and the Il conversion is a real compilation.
4. Mount metadata, verify type security and method integrity
5. Garbage Collection (GC) and exception handling-both are stack-based services. Managed code allows you to dynamically track stacks. To dynamically identify each stack framework, jitter or other compilers must provide a Code Manager.
6. Profiling and error checking services-both depend on the information generated by the source language compiler. Two Mappings must be issued: A ing is sent from the source language structure to the address in the instruction stream, and a ing is sent from the address to the location in the stack framework. When the conversion from Il to the original code is executed, these mappings are recalculated.
7. Management threads and context, as well as remote management-ves provides these services for managed code.
Although this list is incomplete, it is sufficient to let you understand the lower-layer architecture provided by ves Based on the runtime. There will certainly be a book devoted to runtime, and this book will explore various topics in depth.

Conclusion 2.3

In this chapter, I will show you a trip back to the world. I describe how it works when creating, compiling, and configuring a C # program. You have learned the intermediate language (IL) And how metadata is used to describe the type compiled into Il. Both metadata and Il are used for Jitter detection and execution of your code. You can even choose which Jitter to use to execute the application.
The second part of this chapter involves the theory of how to work in this way during runtime. You learned the Virtual Object System (VOS) and the part that makes up it. The common language specification (CLS) is the most interesting for class library designers. It sets rules for Vos-based language interaction operations. Finally, you can see how the virtual execution system (VES) implements vos through ngws runtime.

 

<

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.