In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to achieve selection control in C#, which is very detailed and has a certain reference value. Friends who are interested must finish reading it!
The process control of C# is basically the same as other languages, including:
◆ selection control: if, else, switch, case
◆ cycle control: while, do, for, foreach
◆ jump statements: break, continue
◆ exception handling: try, catch, finally
In the following process, we learn more about the C# selection control.
C# selection Control:
Let's do a simple user authentication, as follows:
Public static void Main () {Console.WriteLine ("Please enter your name"); string username = Console.ReadLine (); if (username! = "") / format: if (condition) {/ / Code to run when the condition is met ("Great {0} Welcome to the Matrix!", username) } the code Console.WriteLine that runs when else// does not meet the {/ / conditions ("you have not entered anything, please leave!");}}
We found that as long as you enter a user, you can log in to the system, so let's set the limit and let the specified person log in, so:
Public static void Main () {Console.WriteLine ("Please enter your name"); string username = Console.ReadLine (); if (username = = "jianle") / / format: if (condition) {/ / Code to run when the condition is met ("Great {0} Welcome to the Matrix!", username) } else if (username = = "boss") {/ / second condition Console.WriteLine ("Great {0} Welcome to the matrix!", username);} else {/ / the code to run when the condition is not met ("you have not entered anything, please leave!");}}
Switch selection control
One day, we need to be able to get more people to log on to the matrix, so we can do this:
Public static void Main () {Console.WriteLine ("Please enter your name"); string username = Console.ReadLine (); switch (username) {case "jianle": Console.WriteLine ("Great {0} host welcomes you to the matrix!", username); break; case "boss": Console.WriteLine ("Great {0} boss welcomes you to the matrix!", username); break Case "cctv": Console.WriteLine ("Great Mr. {0} Welcome to the matrix!", username); break; case "gril": Console.WriteLine ("Great Ms. {0} welcome to the matrix!", username); break; default: Console.WriteLine ("you typed incorrectly, please leave"); break }} above is all the content of the article "how to implement selection Control in C#". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.