Skip to content

Instantly share code, notes, and snippets.

@ebello
Forked from dieseltravis/gist:295062
Created February 4, 2010 23:01
Show Gist options
  • Save ebello/295240 to your computer and use it in GitHub Desktop.
Save ebello/295240 to your computer and use it in GitHub Desktop.
' VB.Net 2.0
' a class for videos is what I was using my original code for
Public Class Video
Private _id As Integer
Public Property Id() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property
' ...other properties, functions, etc.
' a private inner class for storing the ID to look for
Private Class VideoMatcher
Private ReadOnly _videoSearchID As Integer
Sub New(ByVal id As Integer)
_videoSearchID = id
End Sub
' a filtering function to pass into List.Find() as a Predicate
Public Function FindById(ByVal v As Video) As Boolean
Return v.Id = _videoSearchID
End Function
End Class
Public Shared Function FindVideo(ByVal videoList As List(Of Video), ByVal id As Integer) As Video
Return videoList.Find(AddressOf New VideoMatcher(id).FindById)
End Function
End Class
// C# version
public class Video
{
public int Id { get; set; }
// ...other properties, functions, etc.
public static Video FindVideo(List<Video> videoList, int id)
{
return videoList.Find(delegate(Video v) { return v.Id == id; });
}
}
// C# version with lambdas
public class Video
{
public int Id { get; set; }
// ...other properties, functions, etc.
public static Video FindVideo(List<Video> videoList, int id)
{
return videoList.Find(v => v.Id == id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment