Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the features of Category 7.1

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the characteristics of Category 7.1". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the characteristics of Craft 7.1"?

For the first time since 2003, Microsoft considered using a version of C# with decimal places. Currently tentatively, the next version is C # 7.1, which is expected to include asynchronous Main functions (Async Main), default expressions (Default Expression), derived tuple names (Infer Tuple Names), and pattern matching using generics (Pattern-matching with Generics).

Asynchronous Main function

What is most frustrating for developers testing asynchronous code is that console applications currently do not support asynchronous entry points (EntryPoint). Although the workaround is to write multiple lines of boilerplate code, such a pattern depends on the abnormal use of the method and is difficult to understand. For example:

Ublic static void Main () {MainAsync () .GetAwaiter () .GetResult ();} private static async Task MainAsync () {/ / the main code of the program. }

To solve this problem, the following four new function signatures are added to the Asynchronous Main function suggestion, listing the possible entry points.

Static TaskMain () static TaskMain () static TaskMain (string []) static TaskMain (string [])

If another non-asynchronous Main function does not exist in the code, the compiler will generate the required boilerplate code as long as one of the above entry point functions is given. The only limitation is the need for backward compatibility.

Microsoft has considered allowing "async void Main ()", but this complicates the compiler, and Microsoft generally discourages the use of "async void" outside of event handlers.

Default value (that is, Nothing)

VB does not have the keyword "null", which is a subtle difference between C# and VB. But VB has a keyword "Nothing". In the language technical specification, the keyword is described as follows:

Nothing is a special constant. It has no type and can be converted to any type in the type system, including type parameters. After conversion to a particular type, it is equivalent to the default value of that type.

C # currently uses the "default (T)" mode to achieve the same effect, but it is a bit tedious, especially if the name of the class is very long. A "default constant value" (Default Literal) will be provided in C # 7.1, which is described as:

Expressions of this type can be implicitly converted to any types by converting constant values to default values or null values.

The reasoning of this type to default constants works the same way as reasoning to null constants, except that any types are allowed (not just reference types).

Where you can use null, you can usually use default constants as well. This approach is seen as a retrogression in the C# proposal, perhaps because people often frown at two very similar ways to accomplish the same thing. In the minutes of the design meeting, questions were raised:

Are we stirring up a type fight?

An example of using default constant values is as follows:

ImmutableArrayx = default;return default;void Method (ImmutableArrayarrayOpt = default) var x = new [] {default, ImmutableArray.Create (y)}; const int x = default;if (x = default) if (x is default) y = default as RefType / / Compiler Alert: always null. Int I = default

The following example shows the illegal use of default constants:

Const int? Y = default;if (default = = default) if (default is T) var I = defaultthrow default

The latter is undoubtedly a strange component in the design of C#. In the minutes of the design meeting, the following statements are given:

In C #, developers are allowed to throw null. This raises a run-time error, which in turn causes a NullReferenceException exception to be thrown. Therefore, throwing NullReferenceException is not aboveboard, but an ugly model.

There is no reason to allow default values to be thrown. We don't think users will feel that this is feasible or understand how it works.

Instead of introducing default constants, Microsoft considers extending "null" to achieve the same effect. Because "nothing" and "null" are two different keywords in VB, you can do this in VB. Even without keywords, there is the concept of null in VB. As a result, developers can see exceptions like "NothingReferenceException".

Thank you for your reading, the above is the content of "what are the characteristics of Craft 7.1". After the study of this article, I believe you have a deeper understanding of the characteristics of Craft 7.1, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report