C# code to VB.net equivalent [closed]
What is the equivalent of following C# code to VB.net code.
public void RaiseTotalTimeEvent(TotalTimeEventArgs e)
{
EventHandler<TotalTimeEventArgs> temp = TotalTimeEvent;
if (temp != null)
{
temp(this, e);
}
}
EDIT Thanks for the answer.
But all the answers looks like it was converted using some of the existing CODE converter. I have tried Telerik,DeveloperFusion, And others. All these tools generate same code like below and none of these work. Converted Code.
Public Sub RaiseTotalTimeEvent(e As TotalTimeEventArgs)
Dim temp As EventHandler(Of TotalTimeEventArgs) = TotalTimeEvent
RaiseEvent temp(Me, e)
End Sub
Compiler Reports with this error:
Error 8 'Public Event CountEvent(sender As Object, e As CountEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
You should avoid automatically translating code from one language into another. Instead you should learn to understand and rewrite the code to solve the problem in your preferred language.
But there are translators. http://www.developerfusion.com/tools/convert/csharp-to-vb/
I think it will look like this.
Public Sub RaiseTotalTimeEvent(e As TotalTimeEventArgs)
Dim temp As EventHandler(Of TotalTimeEventArgs) = TotalTimeEvent
RaiseEvent temp(Me, e)
End Sub
You could have easily done it by using some on-line C# to VB conversion tool. Anyway below is the equivalent VB code.
Public Sub RaiseTotalTimeEvent(e As TotalTimeEventArgs)
Dim temp As EventHandler(Of TotalTimeEventArgs) = TotalTimeEvent
RaiseEvent temp(Me, e)
End Sub
Look here for an autoconverter: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Public Sub RaiseTotalTimeEvent(e As TotalTimeEventArgs)
Dim temp As EventHandler(Of TotalTimeEventArgs) = TotalTimeEvent
RaiseEvent temp(Me, e)
End Sub
Misses the if, but that should be simple.
精彩评论