I am currently initializing a Hashtable in the following way:
Hashtable filter = new Hashtable(); filter.Add('building', 'A-51'); filter.Add('apartment', '210');
I am looking for a nicer way to do this.
I tried something like
Hashtable filter2 = new Hashtable() { {'building', 'A-51'}, {'apartment', '210'} };
However the above code does not compile.
The exact code you posted:
Compiles perfectly in C# 3. Given you reported compilation problems, I’m guessing you are using C# 2? In this case you can at least do this: