0

以下代表我的代码:

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”代表key,“Intro”代表Header,“My name is vimal”代表Content。

4

1 回答 1

0

要从 a 中获取值,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);
        }
于 2013-03-20T19:50:17.000 回答