Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#中将带有元组的字典拆分为三个不同的字符串?_C#_Asp.net - Fatal编程技术网

如何在C#中将带有元组的字典拆分为三个不同的字符串?

如何在C#中将带有元组的字典拆分为三个不同的字符串?,c#,asp.net,C#,Asp.net,以下是我的代码: Dictionary<string, Tuple<string, string>> headCS = new Dictionary<string, Tuple<string, string>> { }; while (results.Read()) { headCS.Add(results["ID"].ToString(), new Tuple<string, string>(r

以下是我的代码:

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();
Dictionary headCS=新字典{};
while(results.Read())
{
headCS.Add(结果[“ID”].ToString(),
新元组(结果[“文本标题”].ToString(),
结果[“文本内容].ToString());
}
valueIntroduction.InnerHtml=headCS.Values.ElementAt(0.ToString();
valueIntroduction.InnerHtml
中,它既有标题又有内容。现在我想把标题和内容分开。但是我想在字符串中分别获取标题和内容。你知道如何做到这一点吗


上面的Eg输出是
(100,(简介,我的名字是vimal))
。“100”表示键,“Intro”表示标题,“My name is vimal”表示内容。

要从
字典中获取值,需要对
键值对执行
foreach
,如下所示:

        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);
        }
Dictionary headCS=newdictionary();
列表键=新列表();
列表头=新列表();
列表内容=新列表();
foreach(headCS中的KeyValuePair项)
{
//将值打印到控制台
WriteLine(“{0},{1},{2}”,item.Key,item.Value.Item1,item.Value.Item2);
//将的值存储为另一种形式,作为它们所表示内容的示例
key.Add(item.key);
header.Add(item.Value.Item1);
content.Add(item.Value.Item2);
}

您还没有问任何问题。要分割它们,请使用一把小刀