Jan
10
2007
Using the generics Find function
Posted by admin under
.NET 2.0
Mostly a matter of knowing the syntax - so little explaination and more code is the concepf of this article.
Consider this:
public class Player
{
private Int32 m_lId;
private String m_strNamn;
private DateTime m_dtBorn;
}
public class PlayerCollection : System.Collections.Generic.List<Player>
{
}
Now we create the collection and somehow gets the data into it (not shown):
PlayerCollection oColl = new PlayerCollection();
oColl.GetData(...);
And now we want to find the Player with id = 42.
nId = 42;
Player oPlayer = oColl.Find(delegate(Player oPlayer2) { return oPlayer2.Id == nId ; } );
if ( oPlayer != null )
... found...