January 2002
Intermediate to advanced
288 pages
5h 48m
English
Properties are syntactic shorthand for accessor and mutator methods. In place of coding methods that retrieve or modify a particular member variable, properties provide both a get and a set submethod. Support for property style methods can be found in Visual Basic, C#, C++ (using __declspec()) and COM, to name a few. Consider the code snippet in Listing 2.2.
1: class Person {
2:
3: private string name;
4:
5: public void SetName( string Name ) { name = Name; }
6: public string GetName( ) { return name; }
7: }
8:
9: Person me = new Person( );
10: me.SetName( "Richard" );
11: Console.WriteLine( me.GetName( ) );
|
The code in Listing 2.2 shows two methods whose sole purpose is to expose the underlying private ...