开发者

C# code to VB.net equivalent [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For开发者_StackOverflow社区 help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜