Properties Sample: Demonstrates Standard and Indexed Properties for a Managed Class
The Properties sample illustrates how to declare and implement standard and indexed properties for a managed class (
X) using the __property keyword. The managed class exposes two properties:
A simple read-write custom property that allows the user to get and set the value of an integer.
A read-write indexed property that allows the user to get and set an integer value at the specified index.
The sample first creates and initializes the
X class. The
Size property is set (using the
_setSize method) to 4, and the 6th element of the
Value property is set to 2 (using the
_setValue method). The new values are then retrieved using their respective
Get methods and verified.
Building and Running the Sample
To build and run Properties using Visual Studio
- In the Visual Studio IDE, load the solution file properties.sln.
- In Solution Explorer, right-click the properties solution.
- On the shortcut menu, click Build.
- On the Debug menu, click Start.