< Day Day Up > |
The result of some operations can be known at compile time ”for example, the result of the operation 1 + 1 will always be the value 2 , and the result of the operation "a" & "b" will always be the string "ab" . Operations that can be evaluated at compile time are called constant expressions . Constant expressions are more efficient than other types of expressions because the compiler can precompute them at compile time. There are also several places in the language that require constant expressions, such as field initializers. Constant expressions can only contain literals and named constants. The runtime functions Chr , Asc , ChrW , and AscW (see Appendix A) are treated specially by the compiler and can be used in constant expressions, provided that their arguments are also constant expressions. Because string conversions depend on the current thread's culture at runtime, conversions to and from String cannot appear in constant expressions.
|
< Day Day Up > |