namespaceout_ref{//Delegate anonymous method Public Delegate voidMyadd (); classProgram {Static voidMain (string[] args) {Say (Delegate() {Console.WriteLine ("haha, that's so handsome!"); }); Console.readkey (); } Static voidSay (Myadd myadd) {myadd (); } }}
//delegate anonymous method to sum of two numbers Public Delegate intMyadd (intN1,intn2); classProgram {Static voidMain (string[] args) { intA = Sum (Delegate(intN1,intN2) {returnN1 +n2;}); Console.WriteLine (a); Console.readkey (); } Static intSum (Myadd myadd) {returnMyadd (Ten, -); } }
//delegate anonymous method two sum of numbers (2) Public Delegate intMyadd (intN1,intn2); classProgram {Static voidMain (string[] args) {Myadd Add=Delegate(intN1,intN2) {returnN1 +N2;}; intsum = Add (Ten, -); Console.WriteLine (sum); Console.readkey (); } }
C # Delegate------anonymous method