A complete program instruction is called a statement. Each statement ends with a semicolon (;).
All objects, variables, and constants must have a specific type.
Most of the intrinsic types are used for working with numeric values. You will commonly use int for whole numbers and double or float for fractional values.
The char type is used for holding a single character.
The bool type can hold only the value true or false.
A variable is an instance of a type. You initialize a variable by creating it with an assigned value.
You can use the var keyword to create a variable without a type, but only if you assign it immediately. The complier will determine the type of the variable from the value assigned.
You can cast a value from one type to another as long as the compiler knows how to turn the original type into the cast-to type. If no information can be lost, you may cast from one type to another implicitly. If information may be lost, you must cast explicitly. You accomplish the cast by prefacing the variable with the name of the type you want to cast to, in parentheses.
A constant is similar to a variable, but the value cannot be changed while the program is running. Literal constants are simply values used on their own. Symbolic constants, indicated with the const keyword, are values with assigned names, which you use like variables, but the values cannot change.
An enumeration is a value type that consists of a set of named constants.
A string object holds a series of characters (such as a word or sentence). A string literal is simply text enclosed by double quotes. You can assign a string to a string variable, just as you would make any other assignment.
Extra whitespace (spaces, tabs, and newline characters) is ignored by the compiler, unless it appears within a string.
No comments:
Post a Comment