ChetOS.net

C# doesn't support parameterized properties

In VB.net, there is this useful construct:

Public Property DbDictionary(key As String) as String
     Get
          Return _internalDictionary(key)
     End Get
     Set (ByVal value As String)
          _internalDictionary(key) = value
     End Set
End Property


Which will allow you set the index (or key) for a Dictionary object.  This is just one example, but it is very useful.

In C#, this is not available.  It appears that the only workaround is thus:

public string this[string key] {
     get {
          return _internalDictionary(key);
     }
     set {
          _internalDictionary(key) = value;
     }
}


However, notice the this variable.  This method actually sets what VB.net calls a Default Property, so you can only have one of them per class (or multiple if you vary the signature).

This is dumb.
Posted by Chet at 10:49 AM

Comments

I agree!
Posted by Anonymous at 7:22 PM on Wed, Apr 20, 2011

Post a Comment

Feel Free To Share Your Thoughts
You can use [b], [u], [i], and [url]
Optional
Name
Website
© 2013 Chet Zema π