Monday, November 24, 2008

Explicit Conversions Using the Convert Commands

There are many explicit conversions that you can specify in this way, as follows.

Command Result

Convert.ToBoolean ( val ) val converted to bool

Convert.ToByte( val) val converted to byte

Convert.ToChar( val) val converted to char

Convert.ToDecimal( val) val converted to decimal

Convert.ToDouble( val) val converted to double

Convert.ToInt16( val) val converted to short

Convert.ToInt32( val) val converted to int

Convert.ToInt64( val) val converted to long

Here you can see sample program that is use explicit conversion



here is the out put...

Explicit Conversions Using the Convert Commands

There are many explicit conversions that you can specify in this way, as follows.

Looping

By using loop technique you can repeat operation as many time as you want.So you do not write the same code each time.

So we can categorized the main type of loop techniques that are use in C# as follows.

1. do-while loop

2. while loop

3. for loop

Interrupting Loops


Some times you want finger-grained control over the processing of looping code. There are 4 kinds of command in C# to do that task.

1. break - Causes the loop to end immediately

2. continue - Causes the current loop cycle to end immediately

3. goto - Allows jumping out of a loop to a labeled position

4. return - Jumps out of the loop and its containing function



The switch Statement


The switch statement is similar to th if statement in that it executes code conditionally based on the of test.

We can show the basic structure of a switch statement is as above.

Basic C# Console Application Structure

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Output text to the screen.
Console.WriteLine(“The first app in Beginning C# Programming!”);
Console.ReadKey();
}
}
}

The most important section of code at the moment is the following:

static void Main(string[] args)
{
// Output text to the screen.
Console.WriteLine(“The first app in Beginning C# Programming!”);
Console.ReadKey();
}

when we run the above console application this code will executed and will print on the screen “The first app in Beginning C# Programming!”.

In console application in C# to print the output we use " Console.WriteLine( );" .And inside the bracket we should put the message that we want to display.

Basic C# Console Application Structure

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Output text to the screen.
Console.WriteLine(“The first app in Beginning C# Programming!”);
Console.ReadKey();
}
}
}

The most important section of code at the moment is the following:

static void Main(string[] args)
{
// Output text to the screen.
Console.WriteLine(“The first app in Beginning C# Programming!”);
Console.ReadKey();
}

when we run the above console application this code will executed and will print on the s

Basic C# Console Application Structure

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Output text to the screen.
Console.WriteLine(“The first app in Beginning C# Programming!”);
Console.ReadKey();
}
}
}

The most important section of code at the moment is the following:

static void Main(string[] args)
{
// Output text to the screen.
Console.WriteLine(“The first app in Beginning C# Programming!”);
Console.ReadKey();
}

when we run the above console application this code will executed and will