List keys in System.Collections.Generic.Dictionary <string, string>

In debug time, I would like to see which keys in my InitParams collection - I cannot list them.

Initparam

EDIT:

As Jon suggests, this might be a bug in the Silverlight debugger. To reproduce, just create a new Silverlight application in Visual Studio 2010 bug silverlightand simply edit the code

{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            var dictionary = new Dictionary<string, string> {{"A", "1"}, {"B", "2"}, {"C", "3"}};
        }
    }
}
+3
source share
2 answers

Assuming you only need keys, use the property Keys:

foreach (string key in dict.Keys)
{
    ...
}

If you want to simply get all the keys in a readable form in the immediate window, you can use:

string.Join(";", dict.Keys)

pre -.NET 4:

string.Join(";", dict.Keys.ToArray())

... .NET 2, - :

string.Join(";", new List<string>(dict.Keys).ToArray())

, KeyValuePair .

EDIT: , Visual Studio , . , , VS2008:

dictionary in visual studio

... VS2010 . " " " "? , .

+4

Programatically:

foreach (KeyValuePair<string,string> param in InitParams) {
  Debug.Writeline(param.Key + ": " + param.Value);
}

InitParams > Values > Non-Public members > . .

Immediate - InitParams["abc"], , "abc" . , , Debug.

+1

Source: https://habr.com/ru/post/1787883/


All Articles