日期:2014-05-17  浏览次数:20866 次

不规则数据求和求方法
一共 8个 级别
编号:15 24  3  4  5  7  8 (不可改变排序)
数量:48 48 36 36 36 36 36

顺序是固定的  按照顺序排列的
求2个 编号 这间 数量和
比如
TextBox1 = 15
TextBox2 = 4
sum = 48+48+36+36 
------解决方案--------------------

    /// <summary>
    /// 定义一个结构,将编号和index关系起来
    /// </summary>
    struct NumberIndex
    {
        public int index;
        public int number;

        public NumberIndex(int index, int number)
        {
            this.index = index;
            this.number = number;
        }
    }

                    static void Main(string[] args)
        {
            List<NumberIndex> list=new List<NumberIndex>();
            NumberIndex numberIndex=new NumberIndex(0,15);
            list.Add(numberIndex);
            numberIndex=new NumberIndex(1,24);
            list.Add(numberIndex);
            numberIndex=new NumberIndex(2,3);
            list.Add(numberIndex);
            numberIndex=new NumberIndex(3,4);
            list.Add(numberIndex);
            numberIndex=new NumberIndex(4,5);
            list.Add(numberIndex);
            numberIndex=new NumberIndex(5,6);
            list.Add(numberIndex);
            numberIndex=new NumberIndex(6,7);
            list.Add(numberIndex);
            numberIndex=new NumberIndex(7,8);
            list.Add(numberIndex);
            
            Dictionary<NumberIndex,int> dic = new Dictionary<NumberIndex,int>();
            dic.Add(list[0],48);
            dic.Add(list[1],48);
  &nb