none
linq查询或筛选的结果怎么使用啊,强转成要绑定的ObservableCollection类型的集合抛出"未将对象引用设置到对象的实例" RRS feed

  • 问题

  • ObservableCollection<Student> a = new ObservableCollection<Student>();
                Student ab = new Student();
                ab.Name = "1.jpg";
                Student cc = new Student();
                cc.Name = "3.jpg";
                Student bb = new Student();
                bb.Name = "2.jpg";
                Student ww = new Student();
                ww.Name = "aaa";
                Student ss = new Student();
                ss.Name = "bbb";
                a.Add(ab);
                a.Add(cc);
                a.Add(bb);
                a.Add(ww);
                a.Add(ss);
                var query = from Student in a
                            orderby Student.Name ascending /*descending*/
                            select Student;
                a = query as ObservableCollection<Student>;
                foreach (Student k in a)
                {
                    Console.WriteLine(k.Name);
                }
                Console.ReadKey();

    初次使用linq排序或筛选,但不知道怎么使用结果
    2016年11月30日 3:28

答案