Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

Get Key Value from Generic Dictionary Question

Hello all,

I have in MVC this "RouteValueDictionary" and in this it has 3 key value pairs such as this:

Keys:
[0] Data
[1] Total
[2] Errors

Then under Values I have the following if I click on Values:
[0] Count = 1
[1] 1
[2] Count = 1

If I expand the [2] I see:
[0] = {[key, System.Collections.Generic.Dictionary`2[System.String,System.Object]]}

Then under that I see:
Key: "key"
Value: Count = 1

Then I see when I expand the value:
[0] = {[errors, System.String[]]}

Then again I expand the [0] I see:
Key = "errors"
Value = {string[1]}

Then Finally I see what I am trying to get at under value expanded:
[0] = "Error Message"

How do I get to this key value?
Avatar of Cong Minh Vo
Cong Minh Vo
Flag of Viet Nam image

Dictionary<string, string> dic = new Dictionary<string, string>();
        dic["A"] = "Ahmed";
        dic["B"] = "Boys";
        foreach (string mk in dic.Keys)
        {
            if(dic[mk]=="Ahmed")
                Console.WriteLine("key contain \"Ahmed\" is "+mk);
        }
ASKER CERTIFIED SOLUTION
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can try this:
            Dictionary<String, Object> test = new Dictionary<String, Object>();
            Object value = null;
            if (test.TryGetValue("myKey", out value))
                Console.WriteLine("myKey exists.");

Open in new window