a list of wordy delegates
Everything I learn in C#, I like to duplicate in VB.net. Usually I find things a lot easier with VB.net even if it is a little more verbose. However, delegates really suck in VB.net 2.0. You can’t do inline delegates in VB.net 2.0. You can still pass them as parameters, but you can’t create them inline like C#. Instead you have to create a function and pass the address of that function as the parameter.
Public Sub SomeCrazyFunction()
Dim items As New List(of String)
items.Add("Brian")
items.Add("Peter")
items.Add("Lois")
items.Add("Meg")
items.Add("Chris")
items.Add("Stewie")
'-- do some stuff
items.RemoveAll(AddressOf InNotCoolPerson)
'-- do some more stuff
End Sub
Private Function IsNotCoolPerson(ByVal item as String) as Boolean
Return item.Equals("Meg")
End Function
That’s ugly. I think that is much more cumbersome then the C# version. It forces the delegate code to exist in apart from the related code and while you can reuse that function ( where as a delegate, you can’t) I resides out of context from the rest of the code it relates to. In VB.net 3.0, it’s back to the C# style with the introduction of Lambda functions .
items.RemoveAll(Function(s As String) s.Equals("Meg"))
This is even less verbose then C# 2.0 implementation of delegates, but C# got lambdas too. And there code is once again more concise than VB.net.
items.RemoveAll( s => s.Equals("Meg"))