Loop Structures

Loops allow you to repeats a segments of code multiple times. C# has three basic types of loops.You choose the types of loop based on the type of task you need to perform. Your choices are as follows:

- You can loop a set of number of times a for loop.
- You can loop through all the times in a collection of data using a foreach loop.
- You can loop while a certain condition holds true, using a while loop.

Conditional Structures

In many ways, conditional logic(deciding which action to take based on user input, external conditions, or other information), is the heart programming. All conditional logic starts with a condition: a simple expression that can be evaluated to true or false. Your code can them make a decision to execute different logic depending on the outcome of the condition. To build a condition, you can use any combination of literal values or variables along with logical operators.

Date Time Object and TimeSpan Types Object

The DateTime and TimeSpan data types also have built-in methods and properties. These class members allow you to perform three useful tasks:

1. Extract a part of a DateTime(for example, just the year) or convert a TimeSpan to a specific representation(Such as the total number of days or total number of minutes).
2. Easily perform date calculations.
3. Determine the current date and time and other information(such as the day of the week or whether the date occurs in a leap year).

Object Based Manipulation

.NET is object oriented to the core. In fact, even ordinary variables are really full-fledged objects in disguise. This means that comman data types types have the built-in smart to handle basic operations. Even better, it means you can manipulate strings, dates, and numbers in the same way in C# or VB language.
As an example, every type in the .NET class library includes a ToString() method. The default implanation of this methos returns the class name. In simple variables, a more useful result is returned : the string representation of the given variables.
The following code snippet demonstrates how to use the ToString() method with an integer:
string VMyString;
int vMyInteger=100;
vMyString=vMyInteger.ToString();

Type Conversions

Converting information from one data type to another is a fairly common programming task.For example, you might retrieve text input for a user that contains numbers you want to use for a calculation.Or, you might need to take a calculated value and transform it into text you can display in a web page.
Conversion are two types: widening and narrowing.Widening conversion are always succeed.For example, you can convert a 32-bit integer into a 64-integer. You wont need any special code.

Here is an example:

int vMySmallValue;
long vMyLargeValue;
vMySmallValue=Int32.MaxValue;
vMyLargeValue=vMySmallValue;

Advanced Math Operations

Every language has its own set of keywords for common math operations such as rounding and trigonometry. In .NET languages, many of these keywords remain. However, you can also use a centralized Math class that's part of the .NET framework. This has the pleasant side effect of ensuring that the code you use to perform mathematical operations can easily be translated into equivalent statements in any .NET language with minimal fuss.
To use the math operations, you invoke the methods of the System.Math class. These method are static, which means they are always available and ready to use.

The following code snippet shows some sample calculations that you can perform with the math class:

double vMyValye;
vMyValue=Math.Sqrt(81);
vMyValue=Math.Round(42.889,2);
vMyValue=Math.Abs(-10);
VMyValue=Math.Log(24.212);
VMyValue=Math.PI;

Variable Operations

You can use all the standard types of variables operations in C#. When working with numbers, you can use various math symbols. C# follows the conventioal order of operations, performing exponentiation first,followed by multiplication and division and then addition and subtraction. You can also control order by grouping sub expression with parentheses.

int vNumber;
vNumber=4+2*3;
// vNumber will be 10.
vNumber=(4+2)*3;
//vNumber will be 18.

What is SRC ?

The Src(or source) attribute simply specifies where the code that makes up the control being define to be found. Virtual paths are used so the value should be something like "control.ascx" or "/path/control.ascx" and not a physical path like "C:\path\control.ascx."

Once you've added the register directive, the control is registred and can be used just like any other server control. You specify the TagPrefix and TagName in the control's tag just like you would with a built in control and make sure you've got the runat="server" attribute and you've ready to roll.Here's the basic from for a user control's tag:

What is TagName ?

The TagName attribute determine the name by which the control will be refered to. It need to be unique within the namespace, but you can choose whatever you like. Generally name are choosen that are indicative of what the control actually does.

What is TagPrefix ?

The TagPrefix attribute define a namespace in which control will live. You can think of this as the world in which the control will live.Because of this, you can have different controls with the same name and as long as they have a different TagPrefix They can peacfully co-exist on the same page.

What is User Control?

Server Controls are one of the things that makes developing with ASP.NET so simple and powerful at the same time.
Like most everything in ASP.NET there's realy no magic involved with server controls.In fact, you can build your own controls and use them on your pages just like use the ones that ship with .NET.Controls that you build are called user controls.To use it you'll need to specify three attributes: