Asp.net 2.0 tutorial C # BASIC language statements

Source: Internet
Author: User

Respect the author. Keep the words www.it55.com.

The previous sections show how to install the vs2005 programming environment and how to create, compile, compile, and deploy your own Asp.net 2.0 web application. Today, we will unveil the secrets of C #, the main development language of the Asp.net application.
This section focuses on common C # statements.

Reference Microsoft: "C # is a simple, modern, and type-safe object-oriented programming language derived from the C and C ++ languages. C # aims to combine the elevation yield and C ++ flexibility of Visual Basic ." In fact, C # is such a programming language that enables developers to quickly create applications based on the. NET platform. If you do not have the right to speak, first look at the numerical type of C.
1. value type.
Value types include INTEGER (short byte, byte, short integer, unsigned short integer, integer, etc.), Boolean (true and false), character type (including numeric, English, and expressive symbols), real (floating point and decimal), structure, and enumeration
2. reference type.
The reference types include the class type, object type, string type, interface type, array type, and delegate type.
The above many types are boring to understand. Here we will not talk about them one by one. Interested friends can search Google or Baidu on their own.

Main process control statements in C:
I. Condition statements:
1. If statement

If (condition)
{
Execute the statement;
}

Or

If (condition)
{
Execute Statement 1;
}
Else
{
Execute Statement 2;
}

Conditional statements can be nested with each other.

2. Switch statement
 
Switch (reference variable)
{
Case value 1:
Execute Statement 1;
Break;
Case value 2:
Execute Statement 2;
Break;
...
Default: // Default Value
If none of the above values meet the reference variables, execute the statements here;
Break;
}

Ii. Cyclic statements

1. For statement
For (INT I = 0; I <10; I ++)
{
Execute the statement;
}
The operating mechanism of the for statement is as follows: Initialize the declared integer variable I = 0 and judge whether I <10 is true. If yes, continue to execute the statement. If not, exit the loop. If yes, execute the statement, then I increases the number by 1, and then determines whether I <10 is true. If it is true, the statement is executed. If it is not true, the loop is exited.

2. foreach statement
Foreach (element type element in element set)
{
Execute statements for operations on elements;
}
A foreach statement is a statement that traverses and operates all elements in a element set.

3. While statement
While (condition)
{
Execute the statement;
}
If the condition is true, the statement is executed repeatedly. Unless the program is involved.

4. Do-while statement
Do
{
Execute the statement;
}
While (condition)
The only difference between the do-while statement and the while statement is that do-while statements are executed first and then to determine the execution conditions. While statements are executed after judgment.

Iii. Jump statement
1. GOTO statement
For example:
Label1:
Execute statements or functions;
...
Goto label1;

Define a tag in a certain part of the program. When the program needs it, directly jump to the tag through the GOTO statement and execute it down from the tag.

2. Return Statement
The Return Statement directly jumps out of the function and may return a value.
For example:
Return "Return Value ";

3. Break statement
Break is easy to use:
Break;
Purpose: directly jump out of the loop statement or function.

4. Continue statement
Usage:
Continue;
Purpose: jump out of the current cycle and enter the next cycle.

The following example illustrates the differences between break and continue.
For (INT I = 0; I <6; I ++)
{
If (I = 2)
Continue;
If (I> 4)
Break;
Console. writeline (I );
}
The running result is: 0 1 3 4
When I is equal to 2, execute continue, jump out of the current cycle, continue to execute I ++, and enter the next cycle.
When I is equal to 5, run break to exit the for loop, that is, the for loop ends.

Iv. Exception Handling
Statement example:
Try
{
Execute statements that may cause exceptions;
}
Catch (catch exception type)
{
Output the exception information or execute the second execution plan statement. // The statement is executed only when the program captures the exception.
}
Finally
{
The final process of exception handling is usually used to release resources. // The statements here are executed no matter whether an exception occurs.
}

Next, let's further study: classes, attributes, and methods in C #.

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.