Today we will explore what new features from C / CLI in VC 2005. First, C / CLI introduces some new data types Keywords: Ref class / ref structure, value class / value struct, interface class / interface structure, enum class / enum structure, in C / CLI
Class and struct do not have C #, but still remain in C , that is, the default access level is different. In C / CLI, Ref class / ref struct has C #
The language of Class, and the Value Class / Value Struct has Struct's language. Corresponding Interface Class / Interface Struct and Enum Class / Enum Struct
The language of Interface and ENUM in C #. Here, take the Ref class as an example, although they are two words, they together form a keyword, that is,
In C / CLI, the keyword may contain spaces, which is to make multiple words to be understood as a keyword, instead of open them. In C / CLI, keywords are also divided into context sensitive and context, and the keywords mentioned earlier are insensitive, that is, where they appear, they represent it.
Keywords cannot be used as identifiers. The context-sensitive keyword is only the keywords they should appear, otherwise it will not have any special meaning, including
Identifier is used. The newly added context-sensitive data type keywords are: Property, Delegate, and Event, they are basically equal to the corresponding keywords in C #. In addition to the data class, C / CLI also introduces other new keywords: Abstract, New, Override, Sealed, Generic, Where, Finally, GCNew,
Initonly, Literal, Nullptr, which is basically consistent with them in C #, and I will introduce some of the keywords in some C # later. Two new operators, ^ and% are introduced in C / CLI, which are used to support the concept of a new "handle" in C / CLI. In addition, C / CLI has introduced some new language structure.
They are implemented in the type of library, and do not appear as a keyword. In C / CLI, since the hosted stack is introduced, the memory allocation method except that the C original Native stack allocation and heap allocation, there is a distribution on the hosted stack, cooperation
The syntax characteristics of this concept include handles, ^ and% operators, gcnew and other keywords. Below is a code snippet, for example, the case where hosting code is used in C / CLI: Ref class r {private: int m_value; public: prot value {int GET () {return m_value;} void set (int value) {M_value = value;}}}; int main () {r ^ r = gcnew r (); r-> value = 6;} Demonstrate the Usage of Ref Class is hosted, and new Property keywords and Method of hosted object assignment. It can be understood like this, which is a hosted pointer, which is equivalent to the __gc pointer in Managed C , with it to point to a managed object, syntax used to consistent with *, but use GCNew instead of new talents Return one ^ class
Type pointer (called handle). At the same time, the new% operator actually corresponds to C original & operators, but it is used for hosting objects. The new NULLPTR key is equivalent to the NULL key disk in the C #, which is used to represent an empty managed object reference. From this program, it can be seen that C / CLI is much better than Managed C from the syntax level. People who like C often are sensitive to performance, and are also very sensitive to memory allocation. Although in the case of hosting, memory allocation is not a big problem, but in many cases I
They also want to release more control over the object. Use using (...) {} in C # to ensure that it automatically calls its idisposable.dispose () method to release it when the object exceeds a zone.
Resources, C / CLI provides more elegant ways: int main () {r r; r.Value = 6;} This will be, pay attention, it is a managed reference object, so it does not generate on the stack, it is still Will be generated in the hosted stack, but there is a reference to it on the stack, and ensure that when the reference domain is exceeded
Call IDisposable :: Dispose () method. Unfortunately, in the Visual C 2005 Beta 1 I downloaded, this feature does not seem to be realized, the above writer will appear
The method is wrong, it is said to be able to hit the UPDATE patch. C / CLI first say so much, VC's documentation Express Library for Visual Studio / Visual C Express Edition / Reference / C / C Languages / C Language Reference / New C Language Features Comparison Type C / New features in the CLI, through it, can help us understand C / CLI. Visual C 2005 brought us C / CLI, and Visual C # 2005 also brought us new things, and C # 2.0 made a lot of improvements on the basis of C #, especially introduced generics, we will then Experience it.