c# - Referencing multiple methods using one delegate -



c# - Referencing multiple methods using one delegate -

i'm sandpitting delegates. in next illustration dd reference p.m and p.n ? can add together line run p.m 1 time again after adding p.n ? or need implement d dd = p.m; again?

class programme { private delegate int d(int x); static void main(string[] args) { programme p; p = new program(); d dd = p.m;//d dd = new d(p.m); console.writeline(dd(3).tostring()); dd += p.n;//dd += new d(p.n); console.writeline(dd(3).tostring()); //<<is there quick way run p.m ? console.writeline("press [enter] exit"); console.readline(); } private int m(int y) { homecoming y*y; } private int n(int y) { homecoming y*y-10; } }

yes, after first assignment (d dd = this.m;), assignment made using += called.

you may remove method, using -=, refer next sample;

d dd = p.m;//d dd = new d(p.m); console.writeline(dd(3).tostring()); //calls p.m dd += p.n;//dd += new d(p.n); console.writeline(dd(3).tostring()); //calls boths p.m , p.n dd -= p.n; console.writeline(dd(3).tostring()); // calls p.m

c# delegates

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

r - url in CRAN extension manual -

asp.net - .NET Control.ID property inconsistency -