Tuesday, September 30, 2008

My Favourite Anonymous Delegate

Just to test out the editing capabilities here, I'll display a bit of code I use often.
Let's say I have a business entity class to keep some data.


public class MyBusinessEntity
{
public string MyProperty = string.Empty;
}

I keep these business entities in a List


List listToSearch = new List();
// fill the list with actual data

I need to select all business entities that satisfy to a certain criteria.

List listIFound = 
listToSearch.FindAll(delegate(MyBusinessEntity entity)
{
return (entity.MyProperty == "myTestString");
});

listIFound will now contain all instances of MyBusinessEntity from listToSearch where MyProperty equals "myTestString".

by . Also posted on my website

No comments: