Domanda

Sono nel processo di trapianto una prova di unità scritta in VB.NET al più ampio progetto scritto in C #. Tuttavia, questa canzoncina mi ha in cerca di aiuto:

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

Qual è il modo migliore per convertire questo evento? Inoltre, questo è un buon esempio per usare EventHandler<> per consolidare le mie argomentazioni in una struttura?

È stato utile?

Soluzione

In questo caso, si sta effettivamente dimostrando un gestore di eventi contro un evento. C # non ha la clausola nozione Handles che VB.NET ha. Invece è necessario assegnare manualmente un gestore di eventi per un evento in questo modo:

myObject.DataChange += this.object_DataChange;

E di conseguenza, quando hai finito con l'evento si dovrebbe rimuovere il gestore in questo modo:

myObject.DataChange -= this.object_DataChange;

Il gestore di evento reale può essere tradotto come segue.

void object_DataChange(
    int TransactionID,
    int NumItems,
    ref System.Array ClientHandles,
    ref System.Array ItemValues,
    ref System.Array Quantities,
    ref System.Array TimeStamps) {
    ...
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top