Is casting Page.Master to the MasterPage type to access/modify a control considered bad practice?
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.
Is casting Page.Master to the MasterPage type to access/modify a control considered bad practice?
Share
Using the
askeyword 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.