开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜