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

Thursday, October 9, 2008

Creating your first C# program

1.Create a new C# console application project by using Visual studio .

2.And type below coding ad compile it

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();
}
}
}

3.And press the any key to exit from the application.

Brief discussion

1.We used to print the output we use "Console.WriteLine"
2.Here we use "Console.ReadKey();" to detect keyboard input.if we press any key then program will complete it's execution.We used this method here to see out put of the program.otherwise you can't see the output.because it will complete the execution with in second and you can't see the output.to avoid that we use this command.

Thursday, August 14, 2008

C# reference Books

If any one want to get C# reference book please ask me i will provide the link for that.Else I also can send the book that are very useful to learn basic.You can send me a email.My email address is erandika1986@gmail.com.

Wednesday, August 13, 2008

Learning C# With Basic

The aim of putting this blog is give the C# programming knowledge to the beginers