以下代表我的代码:
Dictionary<string, Tuple<string, string>> headCS = new Dictionary<string, Tuple<string, string>> { };
while (results.Read())
{
headCS.Add(results["ID"].ToString(),
new Tuple<string, string>(results["TEXT_HEADER"].ToString(),
results["TEXT_CONTENT"].ToString()));
}
valueIntroduction.InnerHtml = headCS.Values.ElementAt(0).ToString();
在valueIntroduction.InnerHtml
中,它既包含标题,也包含内容。现在我想分别拆分为Header和Content。但我想在字符串中单独获取标题,并在字符串中单独分享内容。知道怎么做到这一点?
例如,上面的输出是(100, (Intro, My name is vimal))
。 “100”表示键,“Intro”表示标题,“我的名字是vimal”表示内容。
答案 0 :(得分:0)
要从Dictionary
中获取值,您需要对foreach
KeyValuePair
进行 Dictionary<string, Tuple<string, string>> headCS = new Dictionary<string, Tuple<string, string>>();
List<string> key = new List<string>();
List<string> header = new List<string>();
List<string> content = new List<string>();
foreach (KeyValuePair<string, Tuple<string,string>> item in headCS)
{
//print values to console
Console.WriteLine("{0},{1},{2}", item.Key, item.Value.Item1, item.Value.Item2);
//store values for in another form just as an example of what they represent
key.Add(item.Key);
header.Add(item.Value.Item1);
content.Add(item.Value.Item2);
}
,如下所示:
{{1}}