1. Variables are temporary memory locations that have a name (called an
identifier), a data type, and a scope. A constant also has a name, data type,
and scope, but it also must have a value assigned to it. The value stored in
a variable can be changed during the execution of the project; the values
stored in constants cannot change.
2. The data type determines what type of values may be assigned to a variable
or constant. The most common data types are string, int, decimal, single,
and bool.
3. Identifiers for variables and constants must follow the C# naming rules and
should follow good naming standards, called conventions. An identifier
should be meaningful and have the data type appended at the end. Variable
names should begin with a lowercase character and be mixed upper- and
lowercase while constants are all uppercase.
4. Intrinsic constants, such as Color.Red and Color.Blue, are predefined and
built into the .NET Framework. Named constants are programmer-defined
constants and are declared using the const statement. The location of the
const statement determines the scope of the constant.
5. The location of the declaration statement determines the scope of the vari-
able. Use the data type without the private or public keyword to declare
local variables inside a method; use the private statement to declare
class-level variables at the top of the program, outside of any method.
6. The scope of a variable may be namespace, class level, local, or block
level. Block level and local variables are available only within the method
in which they are declared; class-level variables are accessible in all
methods within a class; namespace variables are available in all methods
of all classes in a namespace, which is usually the entire project.
7. The lifetime of local and block-level variables is one execution of the
method in which they are declared. The lifetime of class-level variables is
the length of time that the class is loaded.
8. Identifiers should include the data type of the variable or constant.
9. Use the Parse methods to convert text values to numeric before perform-
ing any calculations.
10. Calculations may be performed using the values of numeric variables, con-
stants, and the properties of controls. The result of a calculation may be
assigned to a numeric variable or to the property of a control.
11. A calculation operation with more than one operator follows the order of
precedence in determining the result of the calculation. Parentheses alter
the order of operations.
12. To explicitly convert between numeric data types, use casting or the Con-
vert class. Some conversions can be performed implicitly.
13. The decimal.Round method rounds a decimal value to the specified num-
ber of decimal positions.
14. The ToString method can be used to specify the appearance of values for
display. By using formatting codes, you can specify dollar signs, commas,
percent signs, and the number of decimal digits to display. The method
rounds values to fit the format.
15. try/catch/finally statements provide a method for checking for user
errors such as blank or nonnumeric data or an entry that might result in a
calculation error.
16. A run-time error is called an exception; catching and taking care of excep-
tions is called error trapping and error handling.
17. You can trap for different types of errors by specifying the exception type
on the catch statement, and you can have multiple catch statements to
catch more than one type of exception. Each exception is an instance of the
Exception class; you can refer to the properties of the Exception object for
further information.
18. A message box is a window for displaying information to the user.
19. The Show method of the MessageBox class is overloaded, which means that
the method may be called with different argument lists, called signatures.
20. You can calculate a sum by adding each transaction to a class-level vari-
able. In a similar fashion, you can calculate a count by adding to a class-
level variable.
To learn more about the book this website supports, please visit its Information Center.