Literal Expressions

Literal expressions are composed of constant data.

Details

Details are as follows:

Examples

The following example declares an integer variable named x and initializes it to the literal expression 10.

int x = 10;

The following example declares an integer variable named y and initializes it to the literal expression 0xA using hexadecimal notation. 0xA is equal to the decimal number 10.

int y = 0xA;

The following example declares a string variable named s and initializes it to the literal expression Hello World.

string s = "Hello World";

The following example calculates the square root of the literal expression 3.1415 and assigns it to the variable x.

double x = Math.Sqrt( 3.1415 );

The following example prints the string but creates a new line before World is printed.

string s = "Hello \n World!";