[Language] C # Travel _ ③ _ Condition Statement

Source: Internet
Author: User

Namespace consoleapplication1
{
Class Program
{
Enum holobby {Reading, writing, singing, dancing}
Static void main (string [] ARGs)
{
/* Condition Statement */
Int month;
Month = 0;
/* If statement */
// ① Syntax-If (Boolean) Program Statement
If (month <1)
{
Console. writeline ("the month does not exist! ");
}
// ② Syntax-If (Boolean) Program Statement A else Program Statement B
Month ++;
If (month = 1)
{
Console. writeline ("Today is July 22, January ");
Month ++;
}
Else
{
Console. writeline ("the month does not exist! ");
}
// ③ Syntax-If (Boolean) Program Statement A else if Program Statement B else if Program Statement C... ...

If (month = 1)
{
Console. writeline ("Today is July 22, January ");
}
Else if (month = 2)
{
Console. writeline ("Today is July 22, February ");
}
Else if (month = 3)
{
Console. writeline ("Today is July 22, March ");
}
Else
{
Console. writeline ("the month does not exist! ");
}
// Of course, you can also use multiple boolean values or the ternary operators in the previous section (? :)

/* Switch statement */
// Syntax:
// Switch (parameter)
//{
// Parameter value a corresponding to case: Operation A; break;
// Parameter value B corresponding to case: Operation B; break;
// Default: The default value is C and break;
//}
Int x = 0;
Switch (X)
{
Case 0: console. writeline ("x value: 0"); break;
Case 1: console. writeline ("x value: 1"); break;
Default: console. writeline ("Default execution status"); break;
}

Holobby myholobby = holobby. Dancing; // use of enumeration types -- do you forget to define the enumeration type parameter holobby at the beginning?
Switch (myholobby)
{
Case holobby. Dancing: console. writeline ("I like dancing! "); Break;
Case holobby. Reading: console. writeline ("I like reading! "); Break;
Case holobby. Singing: console. writeline ("I like singing! "); Break;
Case holobby. Writing: console. writeline ("I like writing! "); Break;
Default: console. writeline ("these are not my hobbies! "); Break;
}

Switch (myholobby) // use a combination of case
{
Case holobby. Dancing:
Case holobby. Reading: console. writeline ("I like reading and dancing! "); Break;
Case holobby. Singing:
Case holobby. Writing: console. writeline ("I like writing and singing! "); Break;
Default: console. writeline ("these are not my hobbies! "); Break;
}

Console. readkey (); // wait for the user to enter
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.