开发者

Page.IsPostBack or IsPostBack

开发者 https://www.devze.com 2023-03-04 23:57 出处:网络
I just wanted to know that is there any performance difference between these two statements Pag开发者_高级运维e.IsPostBack

I just wanted to know that is there any performance difference between these two statements

Pag开发者_高级运维e.IsPostBack

or

IsPostBack


There will be a difference at the IL level (an additional getter call in the first case) but it will be so negligible that you shouldn't bother at all.


There is no practical difference. The Page property merely exposes a reference to the same instance as this.


The difference between the execution of both statements will be minimal.

The IsPostBack property belongs to the Page class. It would make the most sense to use your second statement of 'IsPostBack'.

The Page property is actually coming from the Control class, which the Page class eventually inherits. Resolving the Page property will take maybe a few more nanoseconds.


Not really. It would be minor. You shouldn't have to worry about this.


Use IsPostBack.

The Control class exposes a Page property, which of course refers to the containing page. That makes some sense for child controls. The ASP.NET Page class is a descendant of Control, so has a Page property that refers to itself.

When you know you have an instance of Page, and not Controls in general, there is no good reason to use the Page property. It is noise and makes for confusing code.

In code-behind for a page, "this" refers to the Page object. Like any other class in .NET, IsPostback means the same thing as this.IsPostback. Just do what you would for any other property of the current class.

IsPostBack is fractionally faster, and consistent with what you do in all other classes. Page.IsPostBack implies there is magic going on.

0

精彩评论

暂无评论...
验证码 换一张
取 消