Hello all again...
Some monthes ago, while reading professional tutorials, I encountered with a nice implementation (maybe some of you encountered it before, but I think this is a nice syntax to know) and it called Smart Indexer of a specific object.
Look at the example below:
class EranEntity
{
private Hashtable qualities = new Hashtable();
// Indexer (i.e. smart array)
public object this[string key]
{
get { return qualities[key]; }
set { qualities[key] = value; }
}
}
Here, I've created new class called, 'EranEntity' and it contains a Hashtable that holds all of my qualities (and I have a lot of it, as you know... :)). By building this property, it will be much easier to get quality or to update one using 'Dictionary' - the interface is much more readable and easier to use.
Now, lets set some qualities:
public static void Main()
{
// Create EranEntity instance
EranEntity entity = new EranEntity();
entity["smart"] = "very good…";
entity["nice"] = "very nice…";
}
Today in the new world of terms of .NET 2.0, we can also implement this genericly using the new Generics mechanism.
p.s.
Another thing, there is a VS. 2005 quick shortcut to do it by typing the word: indexer (in the editor ofcourse...) and clicking the Tab key until the whole bunch of code is being generated for you to edit.
See you for now...