关于键值对遇到的问题

open382000 2013-06-11 11:47:48
现在有个问题,

比如xml文件


<a>
<p name="xmlfile" value="c://load"/>
<p name="sizeX" value="100">
<p name="sizeY" value="200">
<p name="sizeZ" value="300">
<a>

<a>
<p name="xmlfile" value="c://load"/>
<p name="sizeX" value="100">
<p name="sizeY" value="300">
<p name="sizeZ" value="300">
<a>

<a>
<p name="xmlfile" value="c://load"/>
<p name="sizeX" value="100">
<p name="sizeY" value="400">
<p name="sizeZ" value="300">
<a>




比如我的xml里面有100个上面不同的a标签: 现在我是想根据xmlfile这个value(就是c://load)来判断这个时候我对应的size x, sizey ,sizeZ是多少 可以用键值对吗,还是有什么别的办法。。我想不出来。。好像没有什么可以标识的。
我的思路是:遍历所有的xmlfile添加集合 顺便把sizex sizeY sizeZ也加进去,可是我发现这个行不通。万一有2个xmlfile对应的sizex,sizey sizez相等。我要如何合并他们呢。。就是个数。显示出来。

...全文
80 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
open382000 2013-06-13
  • 打赏
  • 举报
回复
引用 1 楼 caozhy 的回复:
用KeyValuePair<string, Tuple<int, int, int>>
我测试了一下还是达不到需要的


    private Dictionary<string, Tuple<string, string, string, int>> dic = new Dictionary<string, Tuple<string, string, string, int>>();

        private void button3_Click(object sender, EventArgs e)
        {
            string str = this.textBox1.Text;
            string width = this.textBox2.Text;
            string depth = this.textBox3.Text;
            string height = this.textBox4.Text;

            if (dic.ContainsKey(str))
            {
                if (dic[str].Item1.Contains(width))
                {
                    if (dic[str].Item2.Contains(depth))
                    {
                        if (dic[str].Item3.Contains(height))
                        {
                            dic[str] = new Tuple<string, string, string, int>(width, depth, height, dic[str].Item4 + 1);
                        }
                        else
                        {
                            dic[str] = new Tuple<string, string, string, int>(width, depth, height, 1);
                        }
                    }
                    else
                    {
                        dic[str] = new Tuple<string, string, string, int>(width, depth, height, 1);
                    }
                }
                else
                {
                    dic[str] = new Tuple<string, string, string, int>(width, depth, height, 1);
                }
            }
            else
            {
                dic.Add(str, new Tuple<string, string, string, int>(width, depth, height, 1));
            }


        }

        private void button4_Click(object sender, EventArgs e)
        {
           foreach (var key in dic.Keys)
           {
               MessageBox.Show(dic[key.ToString()].Item4.ToString());
           }
        }

测试数据一: 100 100 100 100 单击4次button3 单击button4输出4 改数据 100 100 200 100 单击2次button3 单击button4输出2 少了上面的4 就是被重新赋值了。。我想都在里面 因为数据都是需要的。。又不可以用集合。。因为这样键怎么找到不同的值呢。。 求解
threenewbee 2013-06-12
  • 打赏
  • 举报
回复
用KeyValuePair<string, Tuple<int, int, int>>

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧