Stringify key-value pairs in dictionary
c#, dictionary
Solution
Just to close this
foreach (KeyValuePair<DateTime, string> kvp in dictionary)
{
//textBox3.Text += ("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
Changes to this
foreach (KeyValuePair<DateTime, string> kvp in dictionary)
{
//textBox3.Text += ("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
textBox3.Text += string.Format("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
Problem
I have made a dictionary which contains two values: a `DateTime` and a `string`. Now I want to print everything from the dictionary to a Textbox. Does anybody know how to do this? I have used this code to print the dictionary to the console: ``` private void button1_Click(object sender, EventArgs e) { Dictionary<DateTime, string> dictionary = new Dictionary<DateTime, string>(); dictionary.Add(monthCalendar1.SelectionStart, textBox1.Text); foreach (KeyValuePair<DateTime, string> kvp in dictionary) { //textBox3.Text += ("Key = {0}, Value = {1}", kvp.Key, kvp.Value); Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } } ```