The While in C # is exactly the same as the While statement in VB. When the condition is true, the loop is executed. Inside a While loop, you can use the BREAK statement to skip the cyclic body or use the Continue statement to continue loop operation. Please see the application code of the While statement below:
While (n <10)
{
Console.writeline (n);
N ;
}
DO
The DO cycle in the C # is identical to the DO cycle in the VB, and they are judged at the end of the loop. such as:
DO
{
Console.writeline (n);
N ;
}
While (n <10);
The FOR cycle in the C # is very similar to the FOR cycle in the VB, but the loop variable can be illustrated in the FOR cycle.
Please see the following code:
{
For (int N = 0; n <10; n )
Console.writeline (n);
}
It performs the following:
The variable N is illustrated and the value is 0 as long as n is less than 10, continue to cycle each loop to N increase 1
Foreach
The Foreach in C # is very similar to the for EACH statement in VB. such as:
In VB:
For Each Objitem in Colcollection
.. Execute some code
NEXT
In C #:
Foreach (INT I in arr1) {
.. Execute some code
}
JUMP
C # JUMP statement is like a goto statement in VB to jump from one statement to another.
Break
The BREAK statement is used to end the current loop or Switch statement.
Continue
The Continue statement skips the procedure behind the cyclic body and continues the loop.
Return
Return statement returns to the calling program and returns a value. such as:
Class test
{
Public bool testme ()
{
.. Execute some code
Return True
}
}
Arrays
In C #, you can initialize them while creating array variables. such as:
int [] store = {12}
Take a look at the definition of the multi-dimensional array: Matrix [0] [3] = 4;
An IDentifier is the name for program elements. If we must use the reserved word of other languages in the C # code, you can use an Identifier. In the following code, check is a keyword, @ is idefier:
Public void @Checked ()
Comment
The following is an annotation representation in the C #, which is the same as the usage in Java:
// This is a single row of comments
/ *
* This is a multi-line comment
* /
Conclusion
OK, finally arrived. The above is the concept, grammar and use of the C # language, I don't know if I help you? VB developer, have you seen a familiar term? If the answer is yes, I am gratified ;-)