Wednesday, April 25, 2007

simple declaration and output syntax

Declaring and Creating Arrays

int[] c = new int[ 12 ];

other ways:
int[] c; // declare the array variable
c = new int[ 12 ]; // create the array; assign to array variable

single lines for some variables:
string[] b = new string[ 100 ], x=newstring[ 27 ];




it's suggested that :

For readability, declare only one variable per declaration. Keep each declaration on a separate line and include a comment describing the variable being declared.

common output for printing array elements:
- using for loop
// output each array element's value \
for ( int counter = 0; counter <>
Console.WriteLine( "{0,5}{1,8}", counter, array[ counter ] );

output:

No comments: