Filtering Lists In .NET 2.0

In 3.x+ you can use LINQ and Lambda’s. In 2.0 a nice way to filter lists is by using the FindAll method passing in a search predicate.

List.FindAll Method At MSDN

example:


...
..
.
  return list.FindAll(FilterInsiderFilings);

}

private static bool FilterInsiderFilings(InvestorFilingData investorFilingData)
        {
            // search predicate to filter out insider filings (forms 3, 4, 5)
            if (investorFilingData.Filing == "3" | investorFilingData.Filing == "4" | investorFilingData.Filing == "5")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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