Csharp+asp.net series of Tutorials (v)

Source: Internet
Author: User
Tags foreach bool command line constant continue expression goto numeric
Asp.net| Tutorial This tutorial is written in C # and ASP.net programming tutorials, what are the deficiencies please point out, or the ideal blog message in the old cat.

The long vacation is going to pass. The wallet is empty, and it's going to be a daunting job ... Although a lot of emotion, but the tutorial still want to continue to write, first send a few complaints. ^_^, but the tutorial may have to write slowly later, because the powerless ya! Don't say nonsense to get to the point:
Some netizens said the tutorial is too cumbersome, oh, the following just want to analyze the process control statements, there is a C program based on the skip this paragraph, consider a novice or a brief introduction, detailed also see Professor Tan Haoqiang's "C Language Program design," a book, very strong, it is worth a look.
In C #, there are two selection statements: An If statement, a switch statement.
1.if (Boolean expression)
{
Embedded statements;
}
else if (Boolean expression)
{
Embedded statements;
}
Else
{
Embedded statements;
}//when the value of a Boolean expression is true, the inline statement following the IF is executed.
Just give me a small example, or you'll feel less thorough. Note the introduction of the program entry points in the example of the main () method with parameters, and the IsDigit method of Char.
Using System;
Class Mikecat
{
public static void Main (string[] args)
{
if (args. Length!=1)//Boolean operation to determine the number of parameters
{
Console.WriteLine ("Command line argument can only be one");
}
Else
{
Char c=args[0][0];//here to discuss: the first-dimensional sense is the index of a few parameters, and the second dimension is the index of the number of characters in a parameter. I do not know whether the correct, did not find the relevant information, how do we see??
if ((c>= ' A ') && (c<= ' Z '))
{
Console.WriteLine ("{0} is a capital letter", c);
}
if ((c>= ' a ') && (c<= ' z '))
{
Console.WriteLine ("{0} is a lowercase letter", c);
}
if (Char.isdigit (c))
{
Console.WriteLine ("{0} is number", c);
}
}
}
}
The Main method is the entry point of the program, and program control begins and ends in the method. The method is declared inside a class or struct. It must be static. It can have a void or int return type. Create objects and invoke other methods in the Main method. The Main method can be declared with neither parameters nor parameters.
The Main method can be of type void:
static void Main ()
{
}
It can also return int:
static int Main ()
{
return 0;
}
The Main method can use parameters, in which case it takes one of the following forms:
static int Main (string[] args)
static void Main (string[] args)
The parameter of the Main method is an array of strings representing the command-line arguments. The Length property is usually tested to check for the existence of the parameter, for example:
if (args. Length = = 0)
{
Console.WriteLine ("Please enter a numeric argument.");
return 1;
}
You can also use the Convert class or the Parse method to convert a string parameter to a numeric type. For example, the following statement converts a string to a long number using the Parse method on the Int64 class:
Long num = Int64.parse (args[0]);
You can also use the C # type with alias Int64 long:
Long num = long. Parse (Args[0]);
You can also do the same work using the method ToInt64 of the Convert class:
Long num = Convert.toint64 (s);

Char.isdigit method
Indicates whether a Unicode character belongs to a decimal digit category.
public static bool IsDigit (char);
Indicates whether the character at the specified position in the specified string is classified as a decimal digit.
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.isdigit ("Sample string", 7)); Output: "False"
}
}
2.switch (Control expression)
{
Case constant expression:
Embedded statements;
[Break;]
[goto case Constant expression]
...
Default
Embedded statements;
The}//switch statement is a variant of the IF statement. If you compare a variable or expression with many different values and execute different program segments based on different comparison results.
Note In C # if you want to implement a direct function like C + +, use the goto case and goto default jump statements.

Loop statements are used to repeatedly execute one or more lines of code. There are four kinds of loop statements in C #: While, Do...while, for, foreach statements.
1.while (Boolean expression)
{
Embedded statements;
}//evaluates the value of a Boolean expression. Executes the inline statement once the Boolean expression is true.
As an example, let's say what you need to be aware of: While statements are conditionally repeated inline statements 0 or more times. In the while statement, you can use the break statement to end the loop immediately. Alternatively, you can use the Continue statement to stop the execution of the inline statement and continue with the next loop.
2.do...while statement
The difference with the while statement first executes an inline statement before checking the Boolean expression.
3.for statement
for (Initializer;condition;iterator)
{
Embedded statements;
}//initializer, condition, iterator are optional. Initializer is used to initialize the loop control variable, which can have one or more (separated by commas), condition as a cyclic control condition, or one or more statements; iterator change the value of the loop control variable by law.
4.foreach statement
The foreach statement is newly introduced from C # and does not have this statement in C + +. foreach is used to enumerate each element in the collection and execute an inline statement on each element.
foreach (type identifier in expression)
{
Embedded statements;
The}//type and identifier identifier are used to declare the loop variable, which corresponds to the collection to be enumerated.
Using System;
Using System.Collections;
Class Mikecat
{
public static void Main ()
{
IDictionary Envvars=environment.getenvironmentvariables ();
Console.WriteLine ("Total {0} environment variables", Envvars.) Keys.count);
Loop output each environment variable and its value
foreach (string k in Envvars.) Keys)
{
Console.WriteLine ("{0}={1}", K,envvars[k]. ToString ());//or use Envvars. Value
}
}
}
Also want to analyze the exception control and preprocessing instructions. But confiscated or write so long, the next analysis of these two parts, I hope you pay attention! The questions in this tutorial hope that we can help with the analysis together.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.