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.
|