Question about C#?

Hi I have this code
List<keyvaluepair<string, string>> data = new List<keyvaluepair<string, string>>();
data.Add(new KeyValuePair<string, string>("pdo", "somedata"));
data.Add(new KeyValuePair<string, string>("for", "somedata1"));</string></string></keyvaluepair<string,></keyvaluepair<string,>

here's how to get the value by key
data[1]toString() so then the number
how can you do so you can enter
data["for"]toString() to return somedata1
September 19th 19 at 00:15
2 answers
September 19th 19 at 00:17
I think there is more suitable Dictionary<string, string></string>
September 19th 19 at 00:19
using System;
using System.Collections.Generic;

namespace ListKeyValuePair
{
 class Program
{
 public static void Main(string[] args)
{
 List<keyvaluepair<string, string>> lkvp = new List<keyvaluepair<string, string>>();

 lkvp.Add(new KeyValuePair<string,string>("pdo", "somedata"));
 lkvp.Add(new KeyValuePair<string,string>("for", "somedata1"));

 foreach (KeyValuePair<string, string> kvp in lkvp)
{

 Console.WriteLine("Key= {0}, Value= {1}", kvp.Key, kvp.Value);
}

 Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}</string></string,string></string,string></keyvaluepair<string,></keyvaluepair<string,>

how can you do so you can enter
data["for"]toString() to return somedata1

if you want it that way - use the dictionary (Dictionary class), example:
public static void Main(string[] args)
{
 Dictionary<string, string> dictionary = new Dictionary<string, string>();

 dictionary.Add("cat", "animal");
 dictionary.Add("shark", "fish");

 Console.WriteLine(dictionary["cat"]); 
Console.ReadKey(true);
 }</string></string>

Find more questions by tags C#