. Net 3.0 is actually only an extension library combining PF, CF, WF and cardspace. The core part of. NET 2.0 has not changed, and does not correspond to the New Visual Studio .. Net 3.5 is still inactive. the core of NET 2.0, and its new core component is LINQ. To implement LINQ, it must be improved at the language level, so C # has evolved to version 3.0.
C #3.0 depends on Visual Studio 2008, or. net 3.5 sdk c # compiler, many C #3.0 features are completed by the compiler, C #3.0 +. net2.0 is also a very useful combination. Upgrade from the perspective of product development.. from. NET 2.0. net 3.5, in essence, only expansion, but from the company level, we still need to be cautious. This article mainly talks about the new functions implemented purely by the compiler in C #3.0, that is, the new functions can be compiled using Visual Studio 2008 and run in a simple. NET 2.0 Environment. This article is just a miscellaneous, and does not involve how to use these features, please refer to msdn or otherArticle.
1. Lambda
Lambda has seen it in other languages. python is widely used, and C ++ implements a set of Lambda simulation mechanisms through the boost library. In fact, I do not understand why C #2.0 does not directly introduce lambda, but first implements the anonymous method. There may be two reasons: Time Limit and user education. In C #3.0, it can be said that there is no need to use anonymous method any more. In addition to completely replacing anonymous method, Lambda can also be used with the compiler to generate an Expression Tree, that is, the root of LINQ. Query keywords will be further involved in the discussion of LINQ and Expression Tree.
2. Partial Method
C # I think it is an OO language. Everything is an object and there are no global variables or global functions. However, as an industrial language, it is not enough to support only one paradigm. C #1.0 is Oo, and 2.0 and 3.0 add a lot of functional programming and Generative programming functions, such as generic, lambda, partial class and partial method. Although partial class and partial method are helpful for team development, they are basicallyCodeAutomatically generate the service. Whether the partial method is useful depends, in many ways, on the Design of Automatic code generation by the designer and the proper application, which can improve the development efficiency of the team.
There are several restrictions: no return value (void), no out parameter, implicit declaration as private (So virtual), not for delegate.
3. implicit type inference
First of all, it is clear that C # is a strong type language. implicit type inference for local variables is only for the compiler to help you find the type of variables. For simple types (native and non-Fan Types), using VAR is meaningless or even inencouraging. Explicit types and interfaces should be used. With the introduction of the. NET model, the object type name will become longer and longer. If you have read the implementation of Lambda or tuple in boost, you will understand the long type name brought by the model. The introduction of LINQ has increased this trend. implicit type inference greatly improves code readability andProgramStaff development efficiency.
4. Anonymous type
The anonymous type is still strongly typed, and its most direct use is also LINQ. Anonymous types with the same signature features are generated repeatedly in different assemblies. Therefore, if there is a clear business definition, it is not recommended to use anonymous types. Temporary results returned by LINQ, or local code that implements specific interfaces. using anonymous types can reduce namespace pollution, improve readability, and reduce the chance of errors.
5. object initialization and set Initialization
The code is more readable and concise.
6. Extension Method
There is a type Extension Mechanism in a dynamic language. For example, in Python, the type is also an object, and class methods can be directly extended. Javascript is extended through prototype. C #3.0 is still very clever in implementing class function extensions. It is implemented by the compiler, and templete similar to C ++ is also completed by the pre-processor. It does not violate the open and closed principle and can achieve better code readability.
7. automatically implemented attributes
The functions implemented by the IDE are handed over to the compiler for implementation. Different from C/C ++, there are many compiler implementations, And the C # compiler is controlled in Microsoft, which makes it easier to Improve the compiler. Many functions are very complex to implement through class libraries, such as boost lambda, and the readability is poor. However, the compiler or pre-processor (aspectj) can achieve better results.
Note that get and set must be provided at the same time, and attribute cannot be applied.
8. query keywords
Query keywords are generated in combination with LINQ, which must be dependent on. net3.5 in C #3.0. The compiler generates query keyword into lambda and Expression Tree. This part can be completed by the compiler, but the object types in Expression Tree are all in system. core. defined in the DLL.. Net 3.5 environment is unavailable. Of course, you can also copy several DLL files directly to the. NET target machine for running, but the stability is not guaranteed.
Finally, the industrial languages will always evolve. The C #3.0, Python 3, C ++ tr1, c99, and PHP 5 versions all bring new functions, are these functions used? It is of little use if only functional implementation is the goal, but if you pursue intuitive, elegant design, concise and readable code, and then treat coding as an art, each language improvement brings more possibilities. It requires some skill to control these new functions. The premise is to embrace changes and embrace changes. If you are complacent about the implementation of the function and are limited by your knowledge structure and design habits, you will not be able to enjoy the possibility of new functions.