User Tools

Site Tools


indexers_indexed_property

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
indexers_indexed_property [2018/09/09 04:51] wolfgangriedmannindexers_indexed_property [2018/09/10 04:19] wolfgangriedmann
Line 44: Line 44:
   
 return</code> return</code>
 +
 +Classes with indexed properties can also be used like classes with dynamic arrays. Please see this sample:
 +<code visualfoxpro>class IndexedProperty
 +protect _oValues as Dictionary<string,string>
 +
 +constructor()
 +  _oValues := Dictionary<string,string>{} 
 +return
 +
 +property self[cName as string] as string
 +  get
 +    if _oValues:ContainsKey( cName )
 +      return _oValues[cName]
 +    else
 +      return "< not assigned >"
 +    endif
 +  end get
 +  set             
 +    if _oValues:ContainsKey( cName )
 +      _oValues[cName] := value
 +    else
 +      _oValues:Add( cName, value )
 +    endif
 +end set
 +end property
 +      
 +end class</code>
 +To be used like this:
 +<code visualfoxpro>oObject := IndexedProperty{}
 +oObject["MyProp"] := "Hello X#"   
 +oObject["Prop2"] := "Hello again"
 +System.Console.WriteLine( "MyProp:" + oObject["MyProp"] )
 +System.Console.WriteLine( "Prop2:" + oObject["Prop2"] )
 +System.Console.WriteLine( "Prop3:" + oObject["Prop3"] )</code>
 +
 Please see also this Microsoft article: [[https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/indexers/|https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/indexers/]] Please see also this Microsoft article: [[https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/indexers/|https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/indexers/]]
  
indexers_indexed_property.txt · Last modified: 2018/09/11 08:37 by wolfgangriedmann