First, the basic grammar
1. Data type
Integer type: int, long
Floating-point types: float, double, decimal
Boolean type: BOOL
String Type: String
2. Type conversion
int A;
Double b = 3.14;
A = (int) b;
A = Convert.ToInt32 (b);
a = Int. Parse (B.tostring ());
Int. The value that parse needs to place is a string of type
3. Front + + and after + +
int a = 3;
a++;//a=a+1;
++a;//a=a+1;
Examples of different ex + + and after + +
In an assignment operation, the first + + performs a +1 operation and then assigns a value
After + + is the first to perform the assignment, then perform the +1 operation
4. Conditional operators
? :
String c = a > B? "Yes": "Wrong"; If the relationship is established, execute: before, otherwise execute: after.
Second, the statement
1. Branch statements
Format 1:if () {}
Format 2:if () {}else{}
Format 3:if () {}else if{}...else{}
Format 4 If nesting
Switch case Multiple Select one
Console.WriteLine ("1. Hamburgers"); Console.WriteLine ("2. Chicken Leg"); Console.WriteLine ("3. Chicken Rice Flower"); Console.WriteLine ("4. Chicken Roll"); Console.Write ("Please enter the number of items you would like to eat most:"); ints =int. Parse (Console.ReadLine ()); Switch(s)//the variable name is inside the parentheses { Case 1: Console.WriteLine ("you chose a hamburger! "); Break;//the function is to jump out of the nearest curly brace Case 2: Console.WriteLine ("your choice is chicken leg! "); Break;//the function is to jump out of the nearest curly brace Case 3: Console.WriteLine ("your choice is chicken rice flower! "); Break;//the function is to jump out of the nearest curly brace Case 4: Console.WriteLine ("your choice is chicken roll! "); Break;//the function is to jump out of the nearest curly brace default://equivalent to else (that may not be the above)Console.WriteLine ("wrong number, no this product! "); Break; } console.readline ();
View Code
2. Looping statements
for (int i=1;i<=10; i++) {}
Dead loop: for (;;) {}
While loop
Do While
Do: No matter what the judgment behind you is right, you do it first.
Third, class
Length: Gets the lengths of the strings
Tirm () remove front and rear spaces
Tirmstart () only remove the preceding space
TrimEnd () only remove the trailing spaces
ToUpper () converts all lowercase letters to uppercase
ToLower () converts all uppercase letters to lowercase
IndexOf ("Ax") returns the index number of the first occurrence of the character or string, with a return value of-1. Indicates that the character or string was not found
LastIndexOf ("") returns the index number of the last occurrence of the character or string
Substring intercept string
StartsWith whether to start with a * * string
EndsWith Whether to end with a * * string
Whether the contains ("") contains
Replace replacement
2.Math Class Math Class
Ceiling Ceiling for online access
fLoor floor Remove Line
sqrt Open square root
piπ3.141592
Console.WriteLine (Math.PI);
Round rounding
An odd number. 5 time to get on the line
Even. 5 is the time to get the downline
3.DateTime Time Date Type
should be initialized before use
DateTime dt = new DateTime ();
Get current time
DateTime dt = DateTime.Now;
Console.WriteLine (dt. Month);
Get year dt. Year
Gets the month dt. Month
Get Day dt. Day
Get the hour dt. Hour
Get the Sub dt. Minute
Gets the second dt. Second
Get the day of the week
DayOfWeek d = dt. DayOfWeek;
Add () Increase or decrease
4. Random number Classes
Initialization
Random ran = new random ();
Exception statement: try{}catch{}
Four, array
1. One-dimensional arrays
int [] array = new int [n]{parentheses write n values, no assignment without this bracket};
Array[0] = 1;
ARRAY[1] = 2;
...
Array[n-1] = 5;
Enter the number of classes from the console, put each person's age into an array, ask for the oldest, each person by age sort. Console.Write ("Please enter the number of classes:"); intn =int. Parse (Console.ReadLine ()); int[] Age =New int[n]; for(inti =0; I < n; i++) {Console.Write ("Please enter the age of the {0} individual:", i+1); Age[i]=int. Parse (Console.ReadLine ()); } intAgemax =0; for(inti =0; I < n; i++) { if(Agemax <Age[i]) {Agemax=Age[i]; }} Console.WriteLine ("The maximum age is:"+Agemax); Bubble sort for(inti =0; I < n; i++) { for(intj = i; J < N-1; J + +) { if(Age[i] < age[j+1]) { intZhong =Age[i]; Age[i]= age[j+1]; Age[j+1] =Zhong; } } } for(inti =0; I < n; i++) {Console.WriteLine (age[i]); } console.readline ();
Example
2. Two-dimensional array
int [,] array = new int[4,2];
V. Collection set ArrayList
Initialization, no data type required, no length definition required
When adding data, it can be of different data types.
ArrayList al = new ArrayList ();
for (int i = 0; i <; i++)
{
Al. ADD (int. Parse (Console.ReadLine ()));
}
Al. ADD (1);
Al. Insert (2,4);
Al. Remove (4); Remove the first occurrence of an element
Al. RemoveAt (7); Remove an element from an index location
Console.WriteLine (al. IndexOf (6)); View the index number of the first occurrence of the element
Console.WriteLine (al. LastIndexOf (4)); View the index number of the last occurrence of this element
Al. Clear (); Empty
Cloning
ArrayList al1 = new ArrayList ();
Al1 = (ArrayList) al. Clone ();
Determine if it contains
Console.WriteLine (al. Contains (5));
Number
Console.WriteLine (al. Count);
Sort Ascending
Al. Sort (); in descending order, you need to first rank in ascending order and then flip the collection
al. Reverse (); Vi. Functions: Class 4
1. No parameter no return public void name () {} Program Hanshu = new program (); Hanshu.name ()
2. There is no return public void name (int. a) {} program Hanshu = new Program (); string s= hanshu.name ()
3. There is a parameter return public int name (int a) {}
/4. No parameter has a return public int name () {}
C # Review and organize