Saturday, November 29, 2008

File System Data

Streams

There are two type of streams.

Output: OutPut stream are used when data is written to some external destination,which can be a physical disk file , a network location, a printer or another program.Understanding stream programming opens many advanced posibilities.

Input: Input stream are used to read data into memory or varialbes that your program can access.the most common form of input stream you have worked with so far is the keyboard.An input stream can come from almost any source.

*** In C# the system.IO namespace contains almost all of the classes.

Tuesday, November 25, 2008

Functions

Functions in C# are a means of providing blocks of code that can be executed at any point in an application.

for a example you could have a function to calculates the addition of to numbers.So you can use this function from any point in your code.Also we can think this function as reusable code.

Here you can see simple console application that use a single function.



Return Values


The simplest way to exchange data with a function is to use a return value. Functions that have return values evaluate to that value.

the simple example for the return typle function we can show as below.

String Manipulation

The First thing is you have to know that a string type variable can be treated as a read - only array of char variables.This means that you can access individual characters using syntax like the following:

string myString = "A string";
char myChar = myString[1];

*** However, you can ’ t assign individual characters in this way***

*** As with arrays, you can also get the number of elements using" myString.Length ". This gives you the number of characters in the string:

<> .ToLower() - These enable strings to be converted into lowercase.

<> .ToUpper() - These enable strings to be converted into uppercase.

<> .Trim() - if the user accidentally put an extra space at the beginning or end of their input? In this case, the preceding code won ’ t work.You need to trim the string entered, which you can do using the <> .Trim() command

<> .TrimStart() - will trim spaces from the beginning of a string

<> .TrimEnd() - will trim spaces from the end of a string

<>.PadLeft() - These enable you to add spaces to the left of a string to force it to the desired length.

<> .PadRight() - These enable you to add spaces to the right of a string to force it to the desired length.

You use these as follows

<> .PadX( <> );

eg:

myString = "Aligned";
myString = myString.PadLeft(10);


<> .Split() - converts a string into a string array by splitting it at the points specified.

Monday, November 24, 2008

Arrays

An array is a data structure consisting of a group of elements that are accessed by indexing. In C# each element has the same data type and the array occupies a contiguous area of storage.

Declaring Arrays

Array are declared in the following wai in C#

[ ] ;

eg:

int[ ] myArray;
myArray[10]=5;

or we can define as this,

int[] myArray={1,2,3,5,7,3,5,7};

also we can
declared array as following two ways.

int[] myArray = new int[5] {5, 9, 10, 2, 99};

const int Size = 5;
int[] myArray = new int[Size] {5, 9, 10, 2, 99};


Here the one simple program that use String Array



You can see out put of above progarm in belove


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