Skip to content

Filtering using LINQ using Lists in C#

November 9, 2012

Today has been a particularly tough in programming when you are using Lists and if you don’t want to use projection data in NHibernate but instead filter subsets of data, and do numerous summation of the subset of data.

One particular thing I had to do was to filter a List in C#, the only easiest way to do this in a few lines is LINQ.

Here’s how: –

List<Data> filteredData = data.Where(j => j.ID == name).ToList();

data is the initial data list being filtered, j.ID is the column or field you are checking, and name is the value you are checking against to filter. ToList() turns it into a list.

Make sure though that there is data initially otherwise you always get no data!

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: