Both Method1() and GiveAction() are instance method (as apposed to static methods) and therefor there's no problem at all accessing Method1() from GiveAction(). Now, let's take a look at the code and add some comments to explain what's going on:
classProgram{// An instance field.inti=4;// The only static method in the class, also, the traditional starting point of c# applications.staticvoidMain(string[]args){// Set p as a new instance of the Program class.Programp=newProgram();// Action y1 is initialized with the result of p.GiveAction() which is p.Method1().Actiony1=p.GiveAction();// This execute p.Method1(), so does the next row.y1();y1();Console.WriteLine();}// An instance method returning an Action.privateActionGiveAction(){returnnewAction(Method1);}// An instance method.publicvoidMethod1(){this.i++;}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Both
Method1()
andGiveAction()
are instance method (as apposed to static methods) and therefor there's no problem at all accessingMethod1()
fromGiveAction()
. Now, let's take a look at the code and add some comments to explain what's going on: