views:

71

answers:

4

Hi, I have one asp.net application, and now i am using dataset for data manipulation. recently i started to convert this dataset to List collection. But, in some places i can't work. One is that in my old version i am using datarow[] drow = dataset.datatable.select(searchcriteria). But in List collection there is no method available for finding particular values. Is there any way to select some values according with my search criteria? If Possible. Please help me..

Thanks in advance...

+7  A: 

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 30
var query1 = list.Where(person => person.Age > 30);

// Find each person's name
var query2 = list.Select(person => perons.Name);

You'll need a using directive in your file to make this work:

using System.Linq;

Note that these don't use strings to express predicates and projects - they use delegates, usually craeted from lambda expressions as above.

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.

Jon Skeet
A: 

Hello, Generic list have where extention that is using to filter data. In you case with row array:

var rows = rowsArray.Where(row => row["LastName"].ToString().StartsWith("a"));

if you are using RowsCollection, you need to cast it at first.

var rows = dataTableRows.Cast<DataRow>().Where(row => row["LastName"].ToString().StartsWith("a"));
Danil
+1  A: 

you can also try

var query = from p in list
            where p.Age > 18
            select p;
anishmarokey
A: 
    Using System.Data.Linq;

var result=from i in list
where i.age>45 select i;


using lambda expression please use this Statement


var result=list.where(i=>i.age>45);
programmer4programming