c# - How to assign delegates as methods of some implemented interface -


I have an interface that specifies two zero methods with no parameters, how do I "plug" two < Code> System.Action (T) Can I apply the interface to methods in some squares? In my example below, this will be in zero pushfu (action bar 1, action bar 2) method:

  public interface IFoo {void Bar1 (); Zero Bar2 (); } Public square Bla {stack & lt; IFoo & gt; _fooStack = new stack & lt; IFoo & gt; (); Public Zero PushFoo (IFoo foo) {_fooStack.Push (foo); } Public Zero Pushfu (Action Bar 1, Action Bar 2) {IFoo foo = null; // bar1 and bar2 to assign foo // foo = ...; _fooStack.Push (foo); }}    

public class ActionableFoo: IFoo {Action _bar1, _bar2; Public ActionBulfu (Action B1, Action B2) {_bar1 = b1; _bar2 = b2; } Public Zero Bar1 () {if (_bar1! = Null) _bar1 (); } Public Zero Bar2 () {if (_bar2! = Null) _bar2 (); }}

Then, in your example:

  Public Zero Pushfu (Action Bar 1, Action Bar 2) {IFoo foo = new ActionableFoo (Bar 1 , Bar 2); _fooStack.Push (foo); }    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -