C# 2.0 Events, Indexers, and Properties

PowerDesigner represents C# events, indexers, and properties as standard UML attributes with additional properties as follows:


Event Example

The following example shows the Button class, which contains three events:



Property Example

In the following example, class Employee contains 2 properties. The Setter operation has been removed for property TimeReport:



{
 public class Employee
 {
  private int _Function;
  private int _TimeReport;
  // Property Function
  private int Function
  {
   get
   {
     return _Function;
    }
   set
   {
     if (this._Function != value)
      this._Function = value;
    }
  }
  // Property TimeReport
  private int TimeReport
  {
   get
   {
     return _TimeReport;
    }
  }
 }

Indexer Example

In the following example, class Person contains indexer attribute Item. The parameter used to sort the property is String Name:



public class Person
{
 private Hashtable _childAges;
 // Indexer Item
 private int this[String name]
 {
  get
  {
   return (int)_ChildAges[name];
  }
  set
  {
    _ChildAges[name] = value;
  }
 }
}
Person someone;
someone ["Alice"] = 3;
someone ["Elvis"] = 5;


Created October 7, 2009. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com