1

I'm in the process of transplanting a unit test written in VB.NET to the larger project written in C#. However, this little ditty has me looking for help:

Public Sub object_DataChange(ByVal TransactionID As Integer, _
                             ByVal NumItems As Integer, _
                             ByRef ClientHandles As System.Array, _
                             ByRef ItemValues As System.Array, _
                             ByRef Qualities As System.Array, _
                             ByRef TimeStamps As System.Array) _
                             Handles myObject.DataChange

    '' Does event code here
End Sub

What is the best way to convert this event? Also, is this a good instance to use EventHandler<> to consolidate my arguments into a structure?

1
  • Just a tip. If I'm not mistaken SharpDevelop has a feature to convert VB.net to C# code. So if you have a lot of code to convert, that might be worth checking out. Commented Oct 13, 2009 at 22:15

1 Answer 1

5

In this case, you're actually demonstrating an event handler vs. an event. C# does not have the Handles clause notion that VB.NET has. Instead you must manually assign an event handler to an event like so:

myObject.DataChange += this.object_DataChange;

And correspondingly, when you're done with the event you should remove the handler like so:

myObject.DataChange -= this.object_DataChange;

The actual event handler can be translated as follows.

void object_DataChange(
    int TransactionID,
    int NumItems,
    ref System.Array ClientHandles,
    ref System.Array ItemValues,
    ref System.Array Quantities,
    ref System.Array TimeStamps) {
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.