开发者

Is casting Page.Master to the MasterPage type to access/modify a control considered bad practice?

开发者 https://www.devze.com 2023-03-17 01:41 出处:网络
Is casting Page.Master to the MasterPage type to access/modify a control considered bad pr开发者_如何学Goactice?

Is casting Page.Master to the MasterPage type to access/modify a control considered bad pr开发者_如何学Goactice? I've always heard that casting is expensive. I'm debating gutting all instances of casting to a master page type in this project I've inherited and switching to an event based model. I realize this is a bit subjective, but I can't be the first to have faced this implementation choice. I'm looking for experienced opinions I guess.


Using the as keyword instead of directly casting is considered a better and a 'safer' practice, other than that, there's no problem doing it. If you do it a lot, just consider making it a property with a getter, it will just look much more nicer as casting doesn't seem to play well with the 'looks' of the code. It may also save you a typo.

0

精彩评论

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

关注公众号