RaiseEvent in VB.Net

Hi *

Can someone explain to me how i can handle this linse writen in C# in VB.Net

C#:


{
if (this.ErrorEvent !=null)
this.ErrorEvent(new ArgumentException("blablabla"),null);
}

i tried it like this but it is not workin:

VB:


IfNot (RaiseEvent ErrorEventIsNothing)Then
RaiseEvent ErrorEvent(New ArgumentException("blablabla"),Nothing)
End
If

Thx

Peysche

[1893 byte] By [peysche] at [2007-12-16]
# 1
C# prefers a syntax more near to the actual implementation of events. VB is able to code in both ways.

So instead of



Public Class Sample
Public Event MyEvent ()

Public Sub DoSomething ()
RaiseEvent MyEvent()
End Sub
End Class

You can Write


Public Class Sample
Public Delegate Sub MyEventDelegate()
Public Event MyEvent ()

Public Sub DoSomething ()
RaiseEvent MyEvent
End Sub
End Class

VB creates this delegate invisible to you. C# only allows you the second way and does not have the RaiseEvent keyword. So you have to deal with the delegate itself.



Public Class Sample
Public Delegate Sub MyEventDelegate()
Public Event MyEvent ()

Public Sub DoSomething ()
If Not MyEvent Is Nothing Then
MyEvent()
End If
End Sub
End Class

So for your code, all you have to write is:


RaiseEvent ErrorEvent(new ArgumentException("blablabla"), Nothing)

Ramirez at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...