我用一组数据:
(string id,double le,string name)
如下数据:
(id1,100,A)
(id2,50,A)
(id3,70,A)
(id4,80,B)
(id4,90,B)
(id5,50,C)
(id6,40,C)
(id7,90,C)
...
我想整理成只包含,name中le最大那组,如下所示:
(id1,100,A)
(id4,90,B)
(id7,90,C)
用什么样的数据存储方式比较方便查找,其中id和name不按顺序的。不要用到数据库。数据量不大,就百来个。

解决方案 »

  1.   

    也不想用xml,有没有其他的数据方式。
      

  2.   

    Tuple<string, double, string>
    三元组。
      

  3.   

    只是问存储吗?用List不就好了,元素可以写个类,或用匿名类或者Tuple都可以吧
      

  4.   

    用list也是个好方法,自己添加个类,但三个数据的查找,如何做比较好呢?能不能给个具体的代码,谢谢
      

  5.   


    这个无意中给人家加了难度。。
    人家会告诉你,我用datatable循环很好啊,用你这个干吗。。
    或者更甚者,你这个有问题吧,都报错的
      

  6.   

    我也知道用数据库查找最方便,可我的数据没必要存放到文件中的。只是内存中临时用到的,没必要用数据库。
    不知道谁LINQ用得好的,这个应该能实现。
      

  7.   


    xml不需要写文件可以用啊
    数据结构灵活查询方便
    xml.linq命名空间下的XElement非常好用啊
    查询起来linq也很快
    楼组可以试试
    或者说用Tuple 
    个人习惯用xml 呵呵
      

  8.   


    xml不需要写文件可以用啊
    数据结构灵活查询方便
    xml.linq命名空间下的XElement非常好用啊
    查询起来linq也很快
    楼组可以试试
    或者说用Tuple 
    个人习惯用xml 呵呵
    听起来很不错,能不能帮忙写个代码呢?
      

  9.   

    你这情况,我觉得最大的难题是 group by 问题
    group by name select Ie 可以取到最大值,但是,怎么知道最大值的 id = ? 呢?
      

  10.   


     class Program
        {
            static void Main(string[] args)
            {
                string str = "<list>"
                                + "<item id='1' le='100' name='A'/>"
                                + "<item id='2' le='50' name='A'/>"
                                + "<item id='3' le='40' name='A'/>"
                                + "<item id='4' le='80' name='B'/>"
                                + "<item id='5' le='70' name='B'/>"
                                + "<item id='6' le='20' name='C'/>"
                                + "<item id='7' le='10' name='C'/>"
                                + "<item id='8' le='5' name='C'/>"
                             +"</list>";            XElement list = XElement.Parse(str);
                var query = from i in list.Elements("item")
                            group i by i.Attribute("name").Value into g
                            select new
                            {
                                MaxValue = g.Max(p =>double.Parse(p.Attribute("le").Value))
                            };
                foreach (var i in query)
                {
                    Console.Write(i.MaxValue);
                }
                Console.ReadLine();
            }
        }
    小例子给你
      

  11.   

     List<Tuple<string, double, string>> list1 = new List<Tuple<string,double,string>>()
                {
                    new Tuple<string,double,string>("1",15,"A"),
                    new Tuple<string,double,string>("2",20,"A"),
                    new Tuple<string,double,string>("3",30,"B"),
                    new Tuple<string,double,string>("4",45,"B"),
                    new Tuple<string,double,string>("5",55,"C"),
                    new Tuple<string,double,string>("6",75,"C"),
                    new Tuple<string,double,string>("7",95,"C")
                };            var q = from i in list1
                        group i by i.Item3 into g
                        select new { Value = g.Max(v => v.Item2) };
                foreach (var i in q)
                {
                    Console.WriteLine(i.Value);
                }用Tuple也不难 也写了个参考给你
      

  12.   

    还是这个tuple好,非常感谢。散分了。