switch (expression)
{
case constant Expression 1: statement 1;break;
Case constant Expression 2: statement 2;break;
......
case constant Expression N: statement n;break;
Default: Statement n+1;break;
}
for (expression; expression 2; expression 3)
loop body statement;
Break statement: Interrupts the currently executing loop and jumps out of the loop.
Continue statement: Ignores the statement after continue and goes to the next loop.
The Nforeach statement is used to enumerate each element in the collection and to manipulate each element by executing a loop body. The n syntax is as follows:
foreach (data-type variable in set expression)
{
statement block;
}
Random number: Random r = new Random ();
int M=r.next (1, 100);
The concept of a class
A class is an abstract concept.
Used to describe a set of objects that have the same characteristics (data members) and the same behavior (function members)
Public: Any code can access private: Only members within the class (default) protected: The class and the derived class of the class in which it resides
Internal: In assembly
Method
A method is a member function that displays the behavior of a class or object, with the following syntax: [access modifier] Returns a value type method name ([parameter])
{
Method body
}
public int ADDXY (int x,int y) {return x+y;
}
Classification of methods
Instance method: Default Stuclass stu=new stuclass (); Stu. instance method (); n static method: Q is declared with Static, belongs to a class and cannot be associated with an instance. Call: Class. static method ();
Static methods can only invoke static members.
Some basic knowledge commonly used in one of C # 's Basic articles