However, there are also users who expressed their lack of interest and critics who express concern about the rapid development of this programming language. Some commenters have requested further details and clarifications on the features, while others have provided suggestions for additional ones. TypeScript already has this!įurthermore, the comments on the post indicate a significant level of interest in the C# 12 version and upcoming releases. Also usable in generics and generic type constraints. I think you should introduce a namespace-wide equivalent, maybe introduce a type keyword for that? Also it would be extra cool to also have the option to reify the type alias into something that exists and is reflection-queryable at runtime. Using type aliases seem to only work within the file, unless you define it as a global using, but then the global scope is polluted. On April 11, 2023, the user wrote the following: In addition to this, a user named Muhammad Miftah wrote an interesting comment regarding the usage of aliases. This feature allows developers to give alias names to almost any type, including nullable value types and tuples, like in the following code sample: using Measurement = (string Units, int Distance) By having these aliases, developers can improve the readability of their code and make it easier to understand. Starting from this version, developers will be able to use using directives to abstract actual types and provide friendly names for "confusing or long generic names". Moving on to the third highlight of C# 12 preview is a feature that enables the way to provide an alias to any type. With the new default values on lambdas you’ll have a consistent look for default parameter values on methods, constructors and lambda expressions. These approaches still work but are harder to read and are inconsistent with default values on methods. NET, the author of the original blog post, states the following: Kathleen Dollard, principal program manager. The default value will be emitted in metadata and is available via reflection as the DefaultValue of the ParameterInfo of the lambda's Method property.īefore this preview release, if a developer wanted to provide default values for lambda expression parameters, they had to use local functions or a method called DefaultParameterValue from a specific namespace called. With this feature, developers can now specify and define default values for lambda expression parameters using the same syntax as for other default parameters. In addition to primary constructors, the default values for lambda expression parameters are another preview version feature. Public decimal GPA => grades.Any() ? grades.Average() : 4.0m Public Student(int id, string name) : this(id, name, Enumerable.Empty()) = name.Trim() The following code example shows how a primary constructor can be used in C# 12: public class Student(int id, string name, IEnumerable grades) This feature is designed to simplify the process of creating and initializing objects in C#, allowing for more concise and readable code. With primary constructors, developers now can use the parameters to initialize properties or to include them in the code of methods and property accessors. This feature was previously only available for record type in C# 9 as part of the positional syntax for records, but it will now be extended to all classes and structs. The first highlight is the ability to use primary constructors which allows adding parameters to the class declaration and using them in the class body. While still in the preview version, the C# 12 version introduces the features like primary constructors (for non-record classes and structs), using aliases for any type, and default values for lambda expression parameters. Microsoft has published a detailed release post that announces three new features that will be part of the upcoming release of C# 12.
0 Comments
Leave a Reply. |