".NET Programming Pioneer C #" Chapter 1 C # Introduction

zhaozj2021-02-17  50

".NET Programming Pioneer C #" Chapter 1 C # Introduction Christoph Wille | 2001-9-1

Chapter 1 C # Introduction You are welcome to join the C # world! This chapter will introduce you to C #'s world and answer some related questions, such as: How do you use C #, C and C #, and why C # makes development easier and also makes you feel interesting . Why is another programming language? A question that must be answered: When you have used C or VB engaged in the company's development, do you learn another language? Market-style answer is: "In the field of business calculations, C # will It turned into the primary language used to write "Next Generation Windows Services, shortened to NGWS) applications." This chapter will provide support for parameter requests and display some of C #. This chapter will make your appetite. C # language is evolved from C / C . However, it is modern, simple, fully objective and type safety. If you are a C / C programmer, the learning curve will be flat. Many C # statements have borrowed the language you are free, including expressions and operators. If you don't look carefully, you will simply be used as C . About C # most important point: it is a modern programming language. It simplifies and modern C in the fields of classes, namespace, method overload and abnormal processing. Discard the complexity of C , making it more easy to use, less error. The easy-to-use contribution to C # is reduced by some of C , no longer macro, template and multiple inheritance. Especially for corporate developers, the above functions will only have more trouble rather than benefits. New features that make programming are strict types of security, version control, garbage collection (Garbage Collect). The goals of all these functions are targeting the development of components-oriented software. Before continuing to show more features, I want to stop and explain the various elements of the C # crucial. Simple modern object-oriented type security version Control compatible flexible simple C # has a advantage that C does not have to learn simple. The primary goal of the language is simple. Many functions (it is better to have some features that lack C ) help C # all-round simple. In C #, there is no popular pointer in C . By default, you work in a managed code where you do not allow unsafe operations such as memory. I think there is no C programmer to claim, never use the pointer access to the memory that does not belong to them. Closely related to the pointer "dramatic" is "stupid" operation. In C , there are ::,., And -> operators, they are used for namespace, members, and references. For novices, operators are still a difficult relationship between learning. C # Discard other operators, only single operators "." Now a programmer needs to understand the annotation of nested names. You don't have to remember the implicit type of different processor architecture, even a variety of changes ranges. C # uses a unified type system to abandon C multi-change type system. This system allows you to view various types as an object, which is an original type or a Full-Blown class. Compared to other programming languages, simply type as object processing is not allowed to achieve performance. The boxes and fillings will be explained in detail later, but this technology is basically used only when needed. First, the older programmer may not like it, but integer and Boolean are now finally different data types. This means that the incorrect assignment in the original if statement will now be compiled, because the IF statement only accepts the value of the Boolean type. Never have misuse assault characters as a comparison! C # simultaneously solves excessive things that have been in C have some years.

This excess includes a constant predefined, different character types, and the like. In view of excess forms that have disappeared from the language, it is generally available in C #. Modern you put into learning C # efforts is a big investment because C # is designed for the main language of writing NGWS applications. You will find a lot of features that you can implement or costly with C , just part of the basic features in C #. For enterprise programming languages, new financial data types are very popular. You have used a new decimal data type, which is dedicated to financial computing. If you don't like this ready-made simple type, a new type of data can be easily created according to your application's special needs. I have mentioned that the pointer is no longer part of your programming weapon. Don't be too surprised, comprehensive memory management is no longer your task. Running NGWS provides a garbage collector that is responsible for memory management in the C # program. It is necessary to enhance type security due to memory and applications, so it is necessary to ensure the stability of the application. For C programmers, unusually handling is not new, but it is the main function of C #. The abnormality processing of C # and the difference between C is that it is a cross-language (another function at runtime). Before you don't have C #, you must handle weird HRESULTS, but now it is over because you have used an exceptional robust error. For modern applications, security is the primary, C # will not excera way. It provides metadata syntax for declaring the capabilities and licenses of the following NGWS security modes. Metadata is a key concept of NGWS runtime, which will involve it deeper meaning. Object-oriented you do not expect a new language that does not support object-oriented features? C # Of course, all key object-oriented concepts such as encapsulation, inheritance and polymorphism. Complete C # class mode builds the upper layer of the virtual object system (VOS, Virtual Object System) at the NGWS runtime, and VOS will be described in the following seal. Object mode is only part of the foundation, no longer part of the programming language. You must pay attention to things at first, no longer have global functions, variables, or constants. All things are packaged in a class, including example members (accessible through class cases - objects) or static members (through data types). These make C # codes more easy to read and help reduce potential naming conflicts. The method in the definition class is default and non-virtual (they cannot be rewritten by derived classes). The main argument is that this will eliminate some other original code errors due to occasional reform methods. To rewrite the method, you must have an explicit virtual flag. This behavior not only reduces the virtual function table, but also ensures the correct version of the control. You can use the C to write class, you can use access to a different access level to the class member. C # also supports three access rights of Private, Protected, and Public, and also adds fourth: Internal. Details about access rights will be described in Chapter 5, "Class". How many classes you have created were derived from multiple base classes (ATL programmers, your voting is not just!)? Most of the cases, only from one class. The troubles that multi-base classes are usually more than their solve problems. That is why c # only allows a base class. If you feel multiple inheritance, you can use the interface. A possible problem: there is no pointer in C #, how to imitate it? This question is representative, it provides support for the NGW runtime event mode. Again, I will put a comprehensive explanation of it to the fifth chapter. Type Security I will again select the pointer as an example. Have a pointer in C , you can freely convert it into any type, including stupid things such as moving an int * (integer pointer) into a Double * (double precision pointer).

As soon as the memory supports this operation, it "drove". This is not the type of business-level programming language you imagined. Programability, C # implement the most stringent types of safety to protect themselves and garbage collectors. So you must comply with some of the relevant variables in C #: You cannot use a variable without initialization. For member variables of the object, the compiler is responsible for clearing. And local variables are responsible for clearing. When you use a variable that is not initialized, the compiler will teach you how to do it. The advantage is to avoid errors caused by using variables that are not initialized, and you still don't know how these strange results are generated. C # cancels unsafe type conversion. You cannot convert an integer to a reference type (such as an object), and when it is converted down, C # verifies that this conversion is correct. (That is, the derived class is really born from the class that is converted down.) Boundary check is part of the C #. There will never happen: When the array actually defines N-1 elements, n elements are overprint. The arithmetic operation is likely to overflow the range of final value data types. C # allows these operations to be detected in statement levels or application levels. When the detection overflow is allowed, an exception will be thrown when the overflow occurs. In C #, the reference parameters transmitted are type security. Versionable (Versionable) In the past few years, almost all programmers have to involve well-known "DLL Hell". This problem has different versions of the same DLL name due to multiple applications. Sometimes, the old version of the app works well with the new version of the DLL, but when they interrupt the run. The current version is really a headache. Just like you will be seen in Chapter 8, "Write Components" with C # Write components, NGWS Runtime will provide version support for your written applications. C # can best support version control. Although C # does not ensure the correct version control, it can guarantee version control for programmers. With this support, a developer ensures that when his class library is upgraded, it still retains binary compatibility of the existing customer application. Compatible with C # does not exist in a closed world. It allows you to access different APIs using the general language regulations of the most advanced NGWS (Common Language Specification, Simmon Language Specification). CLS specifies a standard for operation between the internal language of this standard. In order to enhance the compilation of CLS, the C # compiler detects all public exit compilation and lists errors when passing. Of course, you also want to access the old COM object. NGWS is available at COM transparent access. How to integrate the original code will be introduced in Chapter 10, "Internal Operation of Non-Manage Code". OLE automation is a special animal. Anyone who uses C creates an OLE automation project already likes a variety of automated data types. There is a good news is that C # supports them, and there is no more troubled detail. Finally, C # allows you to operate internal operations with an API of a C prototype. You can access the entry point (C's prototype) in any DLL from your application. The feature used to access the original API is called a platform call service (PLAFORM Invocation Services, abbreviation PINOVKE), and Chapter 10 will show some examples of internal operations using the C API. The last section of the flexible last part is likely to remind the programmer. You may ask: "Don't I send the API of the pointer?" You are correct. Not only a few such APIs, but a lot (a bit conservative estimate). This access to the original Win32 code sometimes causes the use of the non-secure class specified pointer (although some of them can be solved due to the support of COM and PINVOKE). Although the default status of C # code is type secure, you can declare that some classes or only declare methods are non-secure types. Such a statement allows you to use pointers, structures, and static allocation arrays.

Safety code and non-security code run in the same management space, which suggests that it will not fall into the column when calling a non-security code from the security code. Small junction C # language evolved from C and C , it was created for companies that would like to sacrifice C a little base function to get more convenient and more productive business developers. C # modern, simple, object-oriented and types of security. Although it draws on many things of C and C , there is still a huge difference between some specific areas such as name space, classes, methods, and abnormalities. C # provides you with convenient features, such as garbage collection, type security, version control, and more. Only "cost" is that the code operation is secure, and the pointer is not allowed. Light is safe to get it. However, if you need a pointer, you can still use them through a non-security code, and when the non-security code is called, you cannot contain columns. TOP

转载请注明原文地址:https://www.9cbs.com/read-29927.html

New Post(0)