Jump statement: Break
Example: for (int i=0;; i++)//no judgment condition, i.e. forever satisfying condition, infinite loop
{
Console.WriteLine ("Hello world!");
if (i==9)
{
Break Jump out of the loop when i=9
}
Continue
if (i==2)
{
Continue End the subsequent statement after the continue, jump directly to the state change, and start the next loop
}
While loop: Returns True or False
int i=0; Initial
while (i<=9)
{
Console.WriteLine ("Hello");
i++; State change (written in curly braces)
}
Do...while ...
int i=0;
do{
i++;
Console.WriteLine (i);
} while (i<0); The output is 1, because the condition is determined after the execution of the process before, each time need to perform a i++, and then Judge I<0.
Exception statement: Prevent program interruption, continue to execute later
while (true)
{
int i;
Try
{
String s= "1.23";
int I=int.parse (s);
{
(Console.WriteLine (i); 1.23 cannot be converted to int, will error)---
}
catch (Exception e)//exception is a class, E is one of its own names, and the parentheses can write any
{
Console.WriteLine (E.massage); Output error Reason
Continue
}
Console.WriteLine (i);
Break
}
Or:
catch (Exception e)
{
Console.WriteLine (E.massage);
}
Finally
{
Console.WriteLine (i);
Console.WriteLine ("Eventually will execute finally" regardless of the error);
}
Type
String class: The String class is a class that contains many methods and properties for handling strings
String
String s= "Hello";
int i=s.length; Gets the length of the string, returning an int value
Console.WriteLine (i)//output result is 5
String s= "Hello"
S=s.trim (); Remove the spaces before and after the string
S.trimstart () remove the preceding space
S.trimend () Remove the trailing spaces
Convert S.toupper () to uppercase
Convert s.tolower () to lowercase
string is indexed, starting from 0
String ss= "abcdef123";
int Cc=ss. IndexOf ("CD");
Console.WriteLine (cc); The result is 2, starting from 0, 0, 1, 2,CD at 2 position
String ss= "Abcdef1cd23";
int Cc=ss. LastIndexOf ("CD");
Console.WriteLine (cc); The result for 7,last is the location of the last CD, starting from 0
BOOL B1=ss. StartsWith ("AB") determines whether a string begins with AB
BOOL B2=ss. EndsWith ("23") determines whether to end with 23
Console.WriteLine (ss. Contains ("CD") to determine if the string contains a CD character segment
Substring: Intercepting strings
Ss. Substring (2,3); starting at position 2 (third position), intercept 3
Ss. Substring (2) starting from 2, intercept to the last
Math class
I=math. ABS\SQRT\CEILING\FLOOR\ROUND\PI (i)
DateTime class
DateTime d=new datetime (1990,01,01);
TimeSpan t=new TimeSpan (3,0,0,0); Parentheses inside for adding days, hours, minutes, seconds
D=d.add (t);
or directly add the time directly using the following statement: D=d.adddays (3); AddHours ... Wait a minute
DateTime.Now//Get system Current time
int s=d.dayofyear;
Console.WriteLine (s); Today is the first day of today, return int type
Console.WriteLine (D.dayofweek); Return to Sunday, week
String ss=d.tostring ("yyyy mm month DD day hh" mm min ss sec ");
Double dd=1.234;
Ss=dd. ToString ("#.00"); #为整数位部分,. 00 is two digits after the decimal point 0, or #.#
Example: Judging whether the date is correct
Try
{
DateTime dt=datetime.parse (Console.ReadLine ()); The date format is incorrect if you cannot convert
Console.WriteLine (DT);
}
Catch
{
Console.WriteLine ("Not the correct effective date")
}
Console. Clear (); Clear information
Example: Mobile number Lottery
String s= "12333333333"
for (int i=0;i<=100,i++)
{
Console. Writeline (s);
Thread.Sleep (20); The parentheses are milliseconds, and the whole sentence means how many milliseconds to delay.
Console.clear ();
Console.WriteLine ("14566667777")
Thread.Sleep (20);
Console.clear ();
}
2014-12-14 Jump statement, while loop, usage of various classes