foreach ( type identifier in arrayName )
statement
learning C Sharp ( c# ) and Java (Homeworks, sample codes, assignments)
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: Escape sequence | Description |
---|---|
\n | Newline. Positions the screen cursor at the beginning of the next line. |
\t | Horizontal tab. Moves the screen cursor to the next tab stop. |
\r | Carriage return. Positions the screen cursor at the beginning of the current linedoes not advance the cursor to the next line. Any characters output after the carriage return overwrite the characters previously output on that line. |
\\ | Backslash. Used to place a backslash character in a string. |
\" | Double quote. Used to place a double-quote character (") in a string. For example, Console.Write( "\"in quotes\"" ); displays "in quotes" |
string format specifiers. | |
Format Specifier | Description |
C or c | Formats the string as currency. Precedes the number with an appropriate currency symbol ($ in the US). Separates digits with an appropriate separator character (comma in the US) and sets the number of decimal places to two by default. |
D or d | Formats the string as a decimal. Displays number as an integer. |
N or n | Formats the string with commas and a default of two decimal places. |
E or e | Formats the number using scientific notation with a default of six decimal places. |
F or f | Formats the string with a fixed number of decimal places (two by default). |
G or g | General. Formats the number normally with decimal places or using scientific notation, depending on context. If a format item does not contain a format specifier, format G is assumed implicitly. |
X or x | Formats the string as hexadecimal. |
1 // Welcome1.cs
2 // Text-printing application.
3 using System;
4
5 public class Welcome1
6 {
7 // Main method begins execution of C# application
8 public static void Main( string[] args )
9 {
10 Console.WriteLine( “Hello world!” );
11 } // end method Main
12 } // end class Welcome1