JAL Computing
|
In this final console project, we demonstrate .NET's support for "methods as properties" with the key words set and get. Most published sample projects use an upper case convention for "properties" declared with set and get such as MyProperty. The key words get and set allow us to write setter and getter functions and access these functions with the convenient dot syntax of a property such as myObject.MyProperty= 1; This project also demonstrates the use of the key word const to create a reference to an immutable String. Source Codeimport System; Learn More About "get", "set"It may help to look at getter and setter methods declared with the key words get and set as "methods that appear as properties", or methods as properties for short. Other languages also support this concept. For instance, ATL C++ dlls support the concept of get and put methods that can be accessed from a scripting language using the dot notation of a property. Any error checking can then be implemented in the set method. In this project, we substitute a error message if the user passed string is a null object or if the string is empty. Learn More About "const"Often we want to refer to a constant value within a class. In this sample project, we have an error message that we want to define at compile time. private const ERROR : String = "Error: Null or Empty String"; By convention, in many languages, references to constant values are in all caps like MAX_SIZE. We declare a constant value using the key word const. In JScript, a constant value can be type less (undeclared type) or typed. (Note that declaring an array of values const does not protect the values in the array from being changed.) |
Send mail to [email protected]
with questions or comments about this web site. Copyright © 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009 ©
|