Expectations for the future of C,
A year of contact with C # is generally a perfect language, but some detailed features are still not perfect. Write down some of my future expectations.
The more powerful generic constraints are similar to the C ++ template. The C # Generic constraints make it easier to write code suitable for multiple types. If there is no generic type, we may need to use the object and perform type conversion, or write a lot of identical code for each type. In terms of generic type constraints, C # Is as strict as ever, but due to the imperfect generic constraints, sometimes I have to write some repeated code. For example, in the following example: public static T Max <T> (T a, T B) where T is int or long or float or double {return a> = B? A: B;} Unfortunately, C # does not yet have this function... System. Math is used to write a Max Method for various types. For more information about C # Generic constraints, see constraints on type parameters. Differences between templates and generics: differences between C ++ templates and C # generics. Namespace range access modifier C # provides an internal access modifier to protect internal types or members of the Assembly. However, in actual development, we often need to drag sub-modules in a program. In order to clearly distinguish the public content of classes in the same submodule from the public content of different submodules, we hope that C # can provide access modification to the namespace range in the future. For example, in the following example: copy the code namespace Moudle {public class Common {...} private class Secret {...}} copy the code to add access modification of the private type, so that the Common can access the Secret. The Secret type is visible in the Moudle namespace and invisible outside the Moudle. Note that the current C # does not allow the namespace element to be declared as private or protected. Youyuan in C ++ can solve this problem, but I guess you do not like friend... Using Internal classes can solve this problem to a certain extent, but it is not free. This problem is even more serious in Unity development because the script component must be written in a separate file and cannot be considered an internal class.