tags:

views:

42

answers:

2

Is there any way that one can encapsulate Dictionary to be a new type like DataDictionary so that instead of needing to change the definition in however many places it is used, it can be changed in only a few. Or should I just wrap this in another class that exposes only the aspects that I need?

+4  A: 

Dictionary is not sealed so if you want a proper sub-type, do

class DataDictionary<K, V> : Dictionary<K,V>
{
}

And another option is :

class DataDictionary<K, V> 
{
   private Dictionary<K,V> _data;

}

Which gives you more freedom to design your own type.
And if you meant "How to eliminate the type-parameters", use something like:

class DataDictionary : Dictionary<string, int>
{
}
Henk Holterman
+1  A: 

You can use using directive on the top of your code file.

using DataDictionary = Dictionary<int,int>

But if you use this DataDictionary in a lot of code files, encapsulation or inheritance are much more preferred.

Vitaliy Liptchinsky