none
Can somebody help me translating this? RRS feed

  • Question

  • Hi,

    I have in C#:

    public event EventHandler<EventArgs<Socket>> ConnectionAccepted = null;
    
    private void OnConnectionAccepted(Socket socket)
                {
                    if(this.ConnectionAccepted != null){
                        this.ConnectionAccepted(this,new EventArgs<Socket>(socket));
                    }
                }
    

    I have tried so far in VB:

    Public Event ConnectionAccepted As EventHandler(Of EventArgs(Of Socket)) = Nothing
    
    Private Sub OnConnectionAccepted(socket As Socket)
    	RaiseEvent ConnectionAccepted(Me, New EventArgs(Of Socket)(socket))
    End Sub

    But no luck, Visual Studio 2015 says: "EventArgs has no type parameters ans so cannot have type arguments"

    any ideas?

    Thanks in advance.



    G.Waters


    Monday, November 6, 2017 5:40 AM

Answers

  • Seems that the generic EventArgs was defined in the C# code or in a library. It is not a standard one. Check the original code. I think that you can also do this:

       Public Event ConnectionAccepted As EventHandler(Of Socket)

       Private Sub OnConnectionAccepted(socket As Socket)

          RaiseEvent ConnectionAccepted(Me, socket)

       End Sub

    The handlers will have a Socket as the second parameter.

    Monday, November 6, 2017 8:19 AM

All replies

  • Seems that the generic EventArgs was defined in the C# code or in a library. It is not a standard one. Check the original code. I think that you can also do this:

       Public Event ConnectionAccepted As EventHandler(Of Socket)

       Private Sub OnConnectionAccepted(socket As Socket)

          RaiseEvent ConnectionAccepted(Me, socket)

       End Sub

    The handlers will have a Socket as the second parameter.

    Monday, November 6, 2017 8:19 AM
  • Thanks, even when VS stop marking it as an error, I have my doubts if this is going to work like that, I'll give it a try asap and will let you know.


    G.Waters

    Monday, November 6, 2017 12:46 PM
  • Hi,

    I have in C#:

    public event EventHandler<EventArgs<Socket>> ConnectionAccepted = null;
    
    private void OnConnectionAccepted(Socket socket)
                {
                    if(this.ConnectionAccepted != null){
                        this.ConnectionAccepted(this,new EventArgs<Socket>(socket));
                    }
                }

    I have tried so far in VB:

    Public Event ConnectionAccepted As EventHandler(Of EventArgs(Of Socket)) = Nothing
    
    Private Sub OnConnectionAccepted(socket As Socket)
    	RaiseEvent ConnectionAccepted(Me, New EventArgs(Of Socket)(socket))
    End Sub

    But no luck, Visual Studio 2015 says: "EventArgs has no type parameters ans so cannot have type arguments"

    any ideas?

    Thanks in advance.



    G.Waters



    Translating may require the entire C# code used and then sometimes some C# methods can not be directly converted to VB.Net. So perhaps reading this Handling and Raising Events can provide some insight. Or not.

    La vida loca

    Wednesday, November 8, 2017 6:41 PM



  • Translating may require the entire C# code used and then sometimes some C# methods can not be directly converted to VB.Net. So perhaps reading this Handling and Raising Events can provide some insight. Or not.

    La vida loca

    John,

    Who says the C# code is correct, there is 10 times more non functional C# code on Internet than for VB, while there are tons of non functioning VB samples on Internet. 

    Viorel is not writing like we do. He has probably the opinion that not telling the truth is polite. But his knowledge about C# is in a way that I do not even investigate it as he writes something about C# (that is not the case as it is about VB).

    (Maybe not polite from me that last comment) :-)


    Success
    Cor




    • Edited by Cor Ligthert Wednesday, November 8, 2017 7:10 PM
    Wednesday, November 8, 2017 7:09 PM