Follow the video to learn C # ASP. NET Third Day

Source: Internet
Author: User

Course Highlights:

Use of If
The use of Swith
The case must be followed by a fixed value, cannot be an expression, cannot be a bool operator
Finally, there's a break.
Unless it's case "1."
Case "2" merger
While if the conditional expression after the while is true, executes the code in {} continuously

for (CODE1;CODE2;CODE3). CODE1: The initialization code of the loop, which runs only once before the start of the loop, and the expression of the Code2,bool type, which is true before each loop is completed, and only true for this loop; Code3 executes once after each loop. For the three paragraph can be omitted, but not lost ";". Break, continue can also be applied to for.

Both for and while code can be converted to each other.

Program code:

If usage

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceIf usage8 {9     class ProgramTen     { One         Static voidMain (string[] args) A         { -Console.WriteLine ("Please enter user name:"); -             stringName =console.readline (); theConsole.WriteLine ("Please enter your password:"); -             stringPassword =console.readline (); -             if(Name = ="Admin"&& Password = ="888888") -             { +Console.WriteLine ("Successful LOGIN!!!"); -  +             } A             Else at             { -                 if(Name! ="Admin") -                 { -Console.WriteLine ("The user name does not exist!!!"); -Console.WriteLine ("Login Failed"); -                 } in                 if(Password! ="888888") -                 { toConsole.WriteLine ("The password is incorrect!!!"); +Console.WriteLine ("Login Failed"); -                 } the             } * Console.readkey (); $         }Panax Notoginseng     } -}
View Code

Switch usage

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceswith Usage {classProgram {Static voidMain (string[] args) {Console.WriteLine ("Please enter the month"); stringmonth =Console.ReadLine (); Switch(month) { Case "1":                 Case "3":                 Case "5":                 Case "7":                 Case "8":                 Case "Ten":                 Case " A": Console.WriteLine ("the number of months you enter is 31 days!");  Break;  Case "2": Console.WriteLine ("The month you enter common year is 28 days and leap year is 29 days");  Break;  Case "4":                 Case "6":                 Case "9":                 Case " One": Console.WriteLine ("the number of months you enter is 30 days!");  Break; default: Console.WriteLine ("the month you entered does not exist!!!");  Break;        } console.readkey (); }    }}
View Code

While usage

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceWhile usage {classProgram {Static voidMain (string[] args) {            //Enter a number and output the maximum value of the input number            intMax =0;  while(true)            {                stringnum =Console.ReadLine (); if(num = ="End") {Console.WriteLine ("End of Cycle"); Console.WriteLine ("The maximum value entered is {0}", Max);                    Console.readkey (); return; }                Else                {                    inti =Convert.ToInt32 (num); if(Max <i) {max=i; }                }            }                   }    }}
View Code

For usage

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceFor usage {classProgram {Static voidMain (string[] args) {             for(intI1 =1; I1 <=9; i1++)            {                 for(intI2 =1; I2 <=9; i2++) {Console.WriteLine ("{0}*{1}={2}", I1, I2, I1 *i2);        }} console.readkey (); }    }}
View Code

Follow the video to learn C # ASP. NET Third Day

Related Article

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.