ASP dot net Programming
Statements
• Compound statements are statements that contain lists of statements enclosed in braces { statements }.
• The enclosed statements should be indented one more level than the compound statement.
• The opening brace should be at the beginning of the line following the line that begins the compound statement and be indented to the beginning of the compound statement. The closing brace should begin a line and be indented to the beginning of the compound statement.
• Braces are used around all statements, even single statements, when they are part of a control structure, such as a if-else or for statement. This makes it easier to add statements without accidentally introducing bugs due to forgetting to add braces.
The following example illustrates a if, if...else, if...else if...else statements:
if (...)
{
// statement
}
// **********************************************************
if (...)
{
// statement
}
else
{
// statement
}
// **********************************************************
if (...)
{
// statement
}
else if (...)
{
// statement
}
else
{
// statement
}
The following example illustrates a for statement:
for (initilization; condition; increment/decrement)
{
// statements
}
The following example illustrates a while statement:
while (condition)
{
// statements
}
The following example illustrates a switch statement:
switch (condition)
{
case 1:
// statements
break;
case 2:
// statements
break;
case 3:
// statements
break;
default:
// statements
break;
}
Blank lines
Blank lines improve readability by setting off sections of code that are logically related. One blank line should always be used in the following circumstances:
• Between the local variables in a method and its first statement
• Between logical sections inside a method to improve readability
• After the closing brace of a code block that is not followed by another closing brace
Wrapping lines
When an expression will not fit on a single line, break it up according to these general principles:
• Break after a comma
• Break after an operator
• Prefer higher-level breaks to lower-level breaks
• Align the new line with the beginning of the expression at the same level on the previous line
Regions
As your code gets longer and longer, it becomes more and more difficult to navigate. While you can select classes and methods from the drop-down list above the main editor window within Visual Studio 2008, you can also group your code into logical regions. Specify regions with the #region keyword and a description at the beginning of the code segment. Use a corresponding #endregion keyword at the end of the segment.
The following example illustrates the use of the #region keyword:
#region Maintenance Classes
// TODO: Verify business logic for operation
// code block
#endregion
Using the #region keyword, you can collapse any region by clicking the plus sign. This collapses the code into a gray line that shows the region description.
Note: While regions may allow you to break up large sections of code, it is not a free pass for creating bloated classes. When necessary, create a separate file to contain additional classes within your business tier. Remember, class files are only physical entities, when compiled the classes and methods will all fall under the namespace defined in the file.
Comment tokens
Comment tokens are keywords that Visual Studio 2008 recognizes and can compile in a list. Using the Task List feature within Visual Studio, you can jump to any point within the code where the token appears. Comments in the code begin with //, followed by the token. Default tokens available via Visual Studio include:
• TODO
• HACK
• UNDONE
• Custom strings defined via Tools > Options > Environment > Task List
Services: - ASP.net Programming Homework | ASP.net Programming Homework Help | ASP.net Programming Homework Help Services | Live ASP.net Programming Homework Help | ASP.net Programming Homework Tutors | Online ASP.net Programming Homework Help | ASP.net Programming Tutors | Online ASP.net Programming Tutors | ASP.net Programming Homework Services | ASP.net Programming