Constant Expressions

 <  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.

Advanced

Because the result of the Chr function also depends on the current runtime culture being used when the function is passed values greater than 128, Chr can only be used in constant expressions if the argument is 128 or less.


 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net