如题,有多组数:a,b一组;x,y一组;a,c一组;a,b一组;x,b一组;
我用什么来存放这些数据,能够根据一组中的第一个数查找到第二个数呢?

解决方案 »

  1.   

                List<cs1> crosspicList = new List<cs1>();            cs1 pupd = crosspicList.Find(delegate(cs1) { return (p.Field1== "a"); });
      

  2.   

    楼主是要这样的吗?
      var arry = new Array[] { new string[] { "a", "b" }, new string[] { "x", "y" }, new string[] { "a", "c" }, new string[] { "a", "b" }, new string[] { "x", "b" } };
     //查找第一个是"a"的所有数组的第二个值
                var second = arry.Where(x => x.GetValue(0).ToString() == "a").Select(x=>x.GetValue(1)).ToList();
      

  3.   

    或者这样,如果数组是int型的,改成int型就可以了 var arry = new Array[] { new string[] { "a", "b" }, new string[] { "x", "y" }, new string[] { "a", "c" }, new string[] { "a", "b" }, new string[] { "x", "b" } };
    //查找第一个是"a"的所有数组的第二个值
                var second = (from q in arry
                             where q.GetValue(0).ToString() == "a"
                             select q.GetValue(1)).ToList();
      

  4.   

    用Dictionary<TKey, List<TValue>>
      

  5.   

    谢谢各位,貌似用Key,要求Key值唯一,但是我的第一个值是可以重复的。
    我用数组排序解决了。
    我将第一个数组成一个数组arr,第二个数组成一个数组another,因为我第一个数是数字的我转换成int比较了。这样我第一个数组对应的index,从第二个数组该index读出的就是对应的值。
    private string[] sortArr(string[] arr,string[] another)
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    for (int j = i; j < arr.Length; j++)
                    {
                        if (int.Parse(arr[i]) > int.Parse(arr[j]))
                        {
                            //string temp = arr[i];
                            //arr[i] = arr[j];
                            //arr[j] = temp;
                            string anotherTemp = another[i];
                            another[i] = another[j];
                            another[j] = anotherTemp;
                        }
                    }
                }
                return another;
            }