This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3271|Reply: 0

[Source] .NET/C# syntax goto statement

[Copy link]
Posted on 5/25/2023 7:40:56 PM | | | |
Requirements: Recently, I was reading other people's articles, I saw a goto keyword, I have never used this keyword, today I specially learned about it, think about the application scenario.

The C# goto statement is used to go directly in a program to the location specified by the label in the program, which is actually made up of an identifier plus a colon.

Assuming that we maintain a mountain project, we can have a simple requirement, assuming that the administrator user directly returns the information without going through various logical checks in the middle, as shown in the figure below:



In factgoto keyword is still syntax sugarAfter the final code is compiled, the complete code will be automatically supplemented according to the requirements, and the goto keyword will not appear, as shown in the figure below:



The hyperlink login is visible.

According to the example given by Microsoft's official documentation, goto statements can also be used in switch statements, such as: a product with an original price of 20 yuan,Different prices are given according to the level of the consumer, as shown in the figure below:




The resulting code is as follows:



Reference:The hyperlink login is visible.





Previous:.NET/C# Uploads files based on byte[] in the file header
Next:.NET/C# uses Span to handle strings with high performance
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com