This tutorial references to the C # and the ASP.NET program design tutorial, if there is any deficiencies, please point out, or
The ideal blog of the old cat.
Long vacation is going to pass. The wallet is also empty, and it is necessary to put it into a nervous job of life ... I feel a lot, but the tutorial is still going to write, first send a few complaints. ^ _ ^, But the tutorial may be written in the future, because the heart is weak! Do not say nonsense into the topic:
Some netizens said that the tutorial is too cumbersome, huh, just analyze the process control statement, there is a decision of the C program design, consider there is novice or brief introduction, please refer to Tan Haqiang Professor "C language program" Design "book, very strong, worth seeing.
In C #, there are two selection statements: if statement, Switch statement.
1.IF (Boolean expression)
{
Embed statement;
}
Else IF (Boolean expression)
{
Embed statement;
}
Else
{
Embed statement;
} // When the value of the Boolean expression is true, the embedded statement behind the IF is performed.
Still give a small example, don't always feel not thorough enough. Note The main () method of the program entry point with the program inserted in the presentation, as well as the Isdigit method of char.
Using system;
Class Mikecat
{
Public static void main (string [] args)
{
IF (args.length! = 1) // Boolean calculation of the number of parameters
{
Console.writeline ("The command line argument can only be one");
}
Else
{
Char c = args [0] [0]; // I want to discuss here: The first dimension is the index of the second parameter, the second dimension is the character number index of a parameter. I don't know if it is correct, I don't find relevant information. What do you think? ?
IF ((c> = 'a') && (c <= 'z')))
{
Console.writeline ("{0} is uppercase letters", c);
}
IF ((c> = 'a') && (c <= 'z')))
{
Console.writeLine ("{0} is lowercase letters", c);
}
IF (Char.IsDigit (C))
{
Console.writeline ("{0} is a number", c);
}
}
}
}
The main method is the entry point of the program, and the program is controlled to start and end in this method. This method is internally declared in the class or structure. It must be static. It can have a VOID or INT return type. Create an object and call other methods in the main method. Declare the MAIN method or not using parameters or parameters.
The MAIN method can be a Void type:
Static void main ()
{
}
It also returns int:
Static int main ()
{
Return 0;
}
The main method can use parameters, in which case it uses one of the following forms:
Static int main (String [] ARGS)
Static void main (string [] args)
The parameter of the main method is a String array indicating the command line parameters. It is usually checked whether the parameters are present by testing the length attribute, for example:
IF (args.length == 0)
{
Console.writeline
Return 1;
}
You can also convert a string parameter into a numeric type using the Convert class or the PARSE method. For example, the following statement uses the PARSE method on the INT64 class to convert the string to the LONG type: long Num = int64.parse (Args [0]);
You can also use the C # type of an aliasing INT64:
Long Num = long.parse (args [0]);
You can also use the CONVERT class method toint64 to complete the same work:
Long Num = Convert.TOINT64 (S);
Char.isdigit method
Indicates if a Unicode character belongs to a decimal number category.
Public static bool isdigit (char);
Indicates whether the characters located at the specified location in the specified string belong to the decimal number category.
Public Static Bool Isdigit (String, Int);
Using system;
Public class isdigitsample {
Public static void main () {
CHAR CH = '8';
Console.writeline (char.isdigit (ch)); // output: "True"
Console.writeline (Char.Indigit ("Sample String", 7)); // Output: "false"
}
}
2.Switch (Control Expression)
{
Case constant expression:
Embed statement;
[Break;]
[goto case constant expression]
...
DEFAULT:
Embed statement;
} // Switch statement is a variant of the IF statement. Different blocks are performed if a variable or expression is compared to many different values and perform different blocks depending on the results of different comparisons.
Note If you want to implement the direct functionality like C / C , use the Goto Case and Goto Default jump statements.
The loop statement is used to repeat one or more lines of code. There are four cyclic statements in C #: While, Do ... while, for, foreach statement.
1.While (Boolean expression)
{
Embed statement;
} // calculate the value of the Boolean expression. When the Boolean expression is true, the embedded statement is performed.
Do not give an example, talk about the part you need to pay attention to: While statement is conditionally repeatedly executed 0 times or multiple times. In the While statement, you can end the loop immediately with the BREAK statement. Alternatively, the CONTINUE statement can be used to stop the execution of the embedded statement, and continue the next cycle.
2.DO ... while statement
Difference to the While Statement First, you want to execute a embedded statement before checking Boolean expressions.
3.FOR statement
For (Initializer; Condition; Iterator)
{
Embed statement;
} // Initializer, Condition, Iterator are optional. Initializer is used to initialize the loop control variable, this variable can have one or more (separated by a comma); Condition is a loop control condition, or one or more statements can also change the value of the loop control variable by law.
4.Foreach statement
This statement does not introduce new, C / C from a new, C / C . Foreach is used to enumerate each element in a collection and perform embedded statements for each element.
Foreach (Type Identifier In Expression)
{
Embed statement;
} // Type Type and identifier Identifier is used to declare loop variables, and the expression corresponding to the enumeration.
Using system;
Using system.collections;
Class Mikecat
{
Public static void main ()
{
IDictionary envvars = environment.getenvironmentviriables ();
Console.writeline ("a total of {0} environment variables", envvars.keys.count;
// cycle output each environment variable and its value
FOREACH (String K in Envvars.Keys)
{
Console.writeline ("{0} = {1}", k, envvars [k] .tostring ()); // or Envvars.Value
}
}
}
I have also wanted to analyze the abnormal control and pre-processing instructions. But if you don't have to stay, you still have written so long, and you will analyze these two parts. I hope everyone will pay attention! The questions in this tutorial hopes everyone to help analyze.