By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 2,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Problem in finding the Dictionary Member Types

P: 1
I am using 3 types of dictionaries.

Expand|Select|Wrap|Line Numbers
  1.  
  2. 1) Dictionary<string, string > d = new Dictionary<string, string>();
  3. 2) Dictionary<string, List<string>> d = new Dictionary<string, List<string>>();
  4. 3) Dictionary<string, Dictionary<string, string>> d = new Dictionary<string, Dictionary<string, string>>();
Now I am using GetDictionaryType Function where I an sending a dictionary object.

In GetDictionaryType() I want to find out which dictionary object has been send.

I am able to check whether type of object is dictionary using following code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dictionary<string, string > d = new Dictionary<string, string>();
  3.       Dictionary<string, List<string>> d = new Dictionary<string, List<string>>();
  4.       Dictionary<string, Dictionary<string, string>> d = new Dictionary<string, Dictionary<string, string>>();
  5.  
  6.       System.Type type = d.GetType();
  7.  
  8.       Type constructed = d.GetType();
  9.       Type generic = type.GetGenericTypeDefinition();
  10.  
  11.       if (generic == typeof(Dictionary<,>))
  12.       {
  13.       }
but I want to find out the type of the members.
Where they are <String, List<string>>
or <string,string>
or <string,Dictionary<string,string>>



Please help me for this.

Thanx in advance
May 7 '09 #1
Share this Question
Share on Google+
1 Reply


100+
P: 344
Hello,
I just tested it and works fine, here is:
Expand|Select|Wrap|Line Numbers
  1.             Dictionary<string, string> d = new Dictionary<string, string>();
  2.             Dictionary<int, string> i = new Dictionary<int, string>();
  3.  
  4.             if (i is Dictionary<int, string>)
  5.             {
  6.                 MessageBox.Show(true.ToString());
  7.             }
Modify it to get your problem solved.
May 11 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.