CabConModding
Facebook
Twitter
youtube
Discord
Contact us
RSS
Menu
CabConModding
Home
New
Top
Premium
Rules
FAQ - Frequently Asked Questions
Games
Fornite
Call of Duty: Black Ops 3
Clash of Clans
Grand Theft Auto 5
Apex Legends
Assassin’s Creed Origins
Forums
Premium
Latest posts
What's new
Latest posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Log in
Register
What's new
Premium
Latest posts
Menu
Log in
Register
Navigation
Install the app
Install
More options
Light Theme
Contact us
Close Menu
Forums
Tech Boards
Computer Programming
Source Code & Tutorial
C# Beginners Series Part 2 | Switch Statements
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Syndicate" data-source="post: 13093" data-attributes="member: 2417"><p>Decided to write this part tonight as i wont be able to release another Part for a few days. </p><p></p><p>*Please also note, most code in this series will be written as im writing the thread, its unlikely but if by some chance i do mess up in the code, please leave a comment below. Remember this series is targeted for beginners, there may be points in the series where i could of coded something more efficiently, however im trying to make it easy for a noob to understand!!*</p><p></p><p>In this part you SHOULD learn how switch statements work and how you can use them!</p><p></p><p></p><p>[PHP]</p><p></p><p> static void Main(string[] args)</p><p> {</p><p> Console.Write("Rate Syndicate Out Of 10!!");</p><p> int marks = int.Parse(Console.ReadLine());</p><p></p><p> switch (marks)</p><p> {</p><p> case 10: // if 10 is entered, execute next code!</p><p> Console.Write("Thank You");</p><p> break; // if conditions arent met, break | jump to next</p><p></p><p> default: // if all is false and a valid value hasent been entered</p><p> Console.Write("Your a **** bruhhh");</p><p> break; </p><p> }</p><p> Console.Read();</p><p> }</p><p> }</p><p>}</p><p>[/PHP]</p><p></p><p>Of course you can have more Case's look below for another example;</p><p></p><p></p><p>[PHP]</p><p>static void Main(string[] args)</p><p> {</p><p> Console.Write("Please Type A Number!");</p><p> int marks = int.Parse(Console.ReadLine());</p><p></p><p> switch (marks)</p><p> {</p><p> case 10: // if 10 is entered, execute next code!</p><p> Console.Write("You Typed 10!");</p><p> break; // if conditions arent met, break | jump to next</p><p></p><p> case 9: // if 9 is entered, execute next code!</p><p> Console.Write("You Typed 9");</p><p> break; // if conditions arent met, break | jump to next</p><p></p><p> case 8: // if 8 is entered, execute next code!</p><p> Console.Write("You Typed 8");</p><p> break; // if conditions arent met, break | jump to next</p><p></p><p> default: // if all is false and a valid value hasent been entered</p><p> Console.Write("You didnt type 10, 9 or 8");</p><p> break; </p><p> }</p><p> Console.Read();</p><p> }</p><p>[/PHP]</p><p></p><p>To all readers, i spend time to write this so if you do go to publish my code on another forum, please credit or just write the thing yourself!</p><p></p><p>Need Any Help? Skype- FourSeasonModz</p></blockquote><p></p>
[QUOTE="Syndicate, post: 13093, member: 2417"] Decided to write this part tonight as i wont be able to release another Part for a few days. *Please also note, most code in this series will be written as im writing the thread, its unlikely but if by some chance i do mess up in the code, please leave a comment below. Remember this series is targeted for beginners, there may be points in the series where i could of coded something more efficiently, however im trying to make it easy for a noob to understand!!* In this part you SHOULD learn how switch statements work and how you can use them! [PHP] static void Main(string[] args) { Console.Write("Rate Syndicate Out Of 10!!"); int marks = int.Parse(Console.ReadLine()); switch (marks) { case 10: // if 10 is entered, execute next code! Console.Write("Thank You"); break; // if conditions arent met, break | jump to next default: // if all is false and a valid value hasent been entered Console.Write("Your a **** bruhhh"); break; } Console.Read(); } } } [/PHP] Of course you can have more Case's look below for another example; [PHP] static void Main(string[] args) { Console.Write("Please Type A Number!"); int marks = int.Parse(Console.ReadLine()); switch (marks) { case 10: // if 10 is entered, execute next code! Console.Write("You Typed 10!"); break; // if conditions arent met, break | jump to next case 9: // if 9 is entered, execute next code! Console.Write("You Typed 9"); break; // if conditions arent met, break | jump to next case 8: // if 8 is entered, execute next code! Console.Write("You Typed 8"); break; // if conditions arent met, break | jump to next default: // if all is false and a valid value hasent been entered Console.Write("You didnt type 10, 9 or 8"); break; } Console.Read(); } [/PHP] To all readers, i spend time to write this so if you do go to publish my code on another forum, please credit or just write the thing yourself! Need Any Help? Skype- FourSeasonModz [/QUOTE]
Verification
Post reply
Forums
Tech Boards
Computer Programming
Source Code & Tutorial
C# Beginners Series Part 2 | Switch Statements
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top