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. |