Anonymous functions in C#
- by Maxim Gershkovich
The following syntax is valid VB.NET code
Dim myCollection As New List(Of Stock)
myCollection.Add(New Stock(Guid.NewGuid, "Item1"))
myCollection.Add(New Stock(Guid.NewGuid, "Item2"))
Dim res As List(Of Stock) = myCollection.FindAll(Function(stock As Stock) As Boolean
If stock.Description = "Item2" Then
Return True
End If
Return False
End Function)
How can I accomplish the same thing in C#? I have tried...
myCollection.FindAll(bool delegate(Stock stock) {
if (blah blah) {
}
});
But it appears I have somehow structured it incorrectly as I get the following error. "Error 1 Invalid expression term 'bool'"