Thursday, February 12, 2009

Creating a Port Scanner with C# Windows Forms Application

This simple application will allows you scan Open port of your PC.And this small application will help to to check the security of your PC.

here we are going to use TCPClient to check whether port is open or not.That means if TCPClient connected with the port then port is Opened.Other wise port is closed.

First We will design the Interface.



And the you can see the coding part below.



And final out put will be look like this.

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.