AddHandler RemoveHandler
What I mean
Public Class Worker
Public Delegate Sub WorkDone(ByVal completedWork As Integer )
Private handlers As New ArrayList()
Public Custom Event WorkCompleted As WorkDone
AddHandler (ByVal value As WorkDone)
If handlers.Count <= 5 Then
handlers.Add(value)
End If
End AddHandler
RemoveHandler(ByVal value As WorkDone)
handlers.Remove(value)
End RemoveHandler
RaiseEvent (ByVal completedWork >As Integer)
If completedWork > 50 Then
For Each handler As WorkDone In handlers
handler.Invoke(completedWork)
Next
End If
End RaiseEvent
End Event
Public Sub DoWork()
For completedWork As Integer = 1 To 10
System.Threading.Thread.Sleep(1000)
RaiseEvent WorkCompleted(completedWork * 10)
Console.WriteLine(completedWork)
Next
End Sub
End Class
Not that I've this capability often (if at all).
Public Module Main2
Rem /* WithEvents */
Dim WithEvents xx As New example
Public Sub Main()
Console.WriteLine("Start")
xx.Test1
Console.WriteLine("End")
End Sub
Private Sub xx_a() Handles xx.a
Console.WriteLine("Foo")
xx.Test2
End Sub
Rem /* wiring up multiple events to the same event handler. */
Private Sub xx_b() Handles xx.a,xx.b
Static i As integer
i +=1
Console.WriteLine("Bar{0}",i)
End Sub
End Module
Public Class example
Public Event a
Public Event b
Public Sub new()
End Sub
Public Sub Test1()
RaiseEvent a
End Sub
Public Sub Test2()
RaiseEvent b
End Sub
End Class
The With keyword to reduce the amount of code written. Base
With Me.Elements
.PropertyA = True
.PropertyB = "Inactive"
' And so on for several more lines
End With
Better LINQ Query support
Dim sm = Aggregate xr In From x In Enumerable.Range(0,100)
Where (x Mod 3 = 0) OrElse (x Mod 5 = 0)
Order By x Descending
Take 10
Into Sum
Try comparing implementing an Interface in vb.net and c#, and you'll prefer vb.net automatically writing the method signatures for you.
This post has been edited by AdamSpeight2008: 12 January 2013 - 07:49 AM

New Topic/Question





MultiQuote





|