When we write a method, say an easy one like
void myMethod()
{
// code here
//
}
and we call it from within Main(), it’s done essentially this way:
Program myProgram = new Program ();
myProgram.myMethod();
Obviously, myProgram is entirely arbitrary (taking into consideration, of course, coding conventions) but what’s up with the reference to Program?
You are declaring your method
myMethodinside a class calledProgram. Since your method is not astaticmethod (i.e. it is notstatic void myMethod()) it requires an instance ofProgramin order to work. Therefore you need to create a new instance ofProgramin order to invokemyProgram.myMethod()on it. IfmyMethodwere static, you could have called it simply byProgram.myMethod()or, since you’re already inside that class to begin with,myMethod()(since the current class name is implied for static methods).