I have a non-static class called ImplementHeaderButtons that contains a non-static public method called Implement . The name of the class and method is not important, the important thing is that they are not static, so they need to be created for use, right?
So I did this:
var implementHeaderButtons = new ImplementHeaderButtons(); implementHeaderButtons.Implement(this, headerButtons);
But then I decided to play a little with him (in fact, I was looking for a way to make it one liner), and I came to the conclusion that the following code works just as well:
new ImplementHeaderButtons().Implement(this, headerButtons);
Now I do not need a variable to store the instance, but my question is: how can I create a new instance of the class on the fly and call its method without saving the instance variable?
I would not be surprised if it does not work as intended, but it is.
source share