在列表与LT选择方法

在列表与LT选择方法

本文介绍了在列表与LT选择方法; T&GT;采集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个asp.net应用程序,现在我使用的数据处理的数据集。最近,我开始这个数据转换为List集合。但是,在一些地方这是行不通的。其一是,在我的旧版本我使用数据行[]卓尔= dataset.datatable.select(searchcriteria)。但列表集合中没有可用于查找特定值的方式。有什么办法,我用我的搜索标准,根据选择一些价值?我想知道,如果这是可能的。请帮我。I have an asp.net application, and now I am using datasets for data manipulation. I recently started to convert this dataset to a List collection. But, in some places it doesn't work. One is that in my old version I am using datarow[] drow = dataset.datatable.select(searchcriteria). But in the List collection there is no method available for finding particular values. Is there any way for me to select some values according with my search criteria? I want to know if this is possible. Please help me.推荐答案好了,开始与列表&LT; T&GT; 的不的有 的FindAll 和的 ConvertAll 方法 - 但更地道,现代的方法是使用LINQ:Well, to start with List<T> does have the FindAll and ConvertAll methods - but the more idiomatic, modern approach is to use LINQ:// Find all the people older than 30var query1 = list.Where(person => person.Age > 30);// Find each person's namevar query2 = list.Select(person => person.Name);您将需要一个使用指令在你的文件,以使这项工作:You'll need a using directive in your file to make this work:using System.Linq;请注意,这些不使用字符串来恩preSS predicates和项目 - 他们使用的代表,通常是从如上拉姆达前pressions创建Note that these don't use strings to express predicates and projects - they use delegates, usually created from lambda expressions as above.如果拉姆达前pressions和LINQ是新的给你,我会建议你得到一本书涵盖LINQ第一,如的 LINQ行动,临LINQ ,的C# 4果壳中的或我自己的 C#在深度。你肯定可以的距离的网络教程学习LINQ,但我认为这是一个如此重要的技术,这是值得花时间来彻底了解它。If lambda expressions and LINQ are new to you, I would suggest you get a book covering LINQ first, such as LINQ in Action, Pro LINQ, C# 4 in a Nutshell or my own C# in Depth. You certainly can learn LINQ just from web tutorials, but I think it's such an important technology, it's worth taking the time to learn it thoroughly. 这篇关于在列表与LT选择方法; T&GT;采集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 09:54