Thursday, January 20, 2011

How to use predicate in generics list of class type in c#.net

From these below lines you can check if a particular value is present in the list or not. And If exists you will get the index of the particular item in the list.

Here the list is lstMessages

if (lstMessages.Exists(delegate(Messages m) { return m.MessageID == Convert.ToInt64(dr["MessageID"]); }))
{

int index = lstMessages.FindIndex(delegate(Messages m) { return m.MessageID == Convert.ToInt64(dr["MessageID"]); });
}

This is the one way of using predicate in generics list class. You can also check some C#.Net articles here.

No comments:

Post a Comment