Why can I create an instance of a class without storing it to a variable and still have everything work?

前端 未结 3 1020
南方客
南方客 2021-01-20 00:28

I have a non-static class called ImplementHeaderButtons which contains a non-static public method called Implement. The name of the class and metho

3条回答
  •  执笔经年
    2021-01-20 01:21

    Your call to new ImplementHeaderButtons() returns an instance of ImplementHeaderButtons. Then, you call .Implement() on that instance.

    Think of it like this:

    (new ImplementHeaderButtons()).Implement(this, headerButtons);
    

提交回复
热议问题