c# - Pass a delegate itself as a parameter -


Is this method possible to pass a delegate or event in C # so that the method is a new event handler Representative with + = (and not that method can call the representative)?

Let's say I can mix C ++ with C #, this will be what I'm looking for:

  Public Class Mikalas {Public Action * Action Pert; Assigned public zeros (action * action) {actionPtr = action; (* Verb) + = some method; } Public Zero Drawing () {(* action) - = SomeMethod; } Some method () {// Do stuff}}  

Hope this makes sense.

Event: No (unless you were in that category where the event is defined). It is implemented by the C # compiler.

Plain old representative: Pass yes as the ref parameter. (Think about this like this: How do you add a handler to a representative? You use + = , okay? This is an assignment operator, Which is stable: You are specifying the representative in a new representative example that contains the specified method to the right of + = , just like x + = 1 to X to x + 1 . Only once you can assign an external variable to a method Within a new value or object when it was passed as ref or Out parameter).

For example, the following code leaves list untouched:

  list & lt; Int & gt; List = null; InitializeListImproperly (list); Fixed zero start initialListImproperly (list & lt; int & gt; x) // // is a local variable, so this list is outside the variable / outside of this field! X = new list & lt; Int & gt; {1, 2, 3}; }  

The following is a new list & lt; Int & gt; :

  list & lt; Int & gt; List = null; Preliminary list (referee list); Fixed zero start initialListProperly (reference list & lt; int & gt; x) {x = new list & lt; Int & gt; {1, 2, 3}; }  

This is the same principle.


Comments