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.
Generic List<T>
have the Where<T>(Func<T, Boolean>)
extension method that can be used to filter data.
In your case with a row array:
var rows = rowsArray.Where(row => row["LastName"].ToString().StartsWith("a"));
If you are using DataRowCollection
, you need to cast it first.
var rows = dataTableRows.Cast<DataRow>().Where(row => row["LastName"].ToString().StartsWith("a"));
Try this:
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);
you can also try
var query = from p in list
where p.Age > 18
select p;
I have used a script but to make a join, maybe I can help you
string Email = String.Join(", ", Emails.Where(i => i.Email != "").Select(i => i.Email).Distinct());
Source: Stackoverflow.com