The most practical use I've found relates to COM interaction scenarios. Many legacy COM components end up generating signatures that are unsuitable for use with managed code without a lot of castings due to the fact that many elements become marshaled as an object . This leads to the following code.
IUser GetAUser() { ... } IUser user = GetAUser(); IAddress address = (IAddress)user.GetAddress(); int zipCode = (int)address.GetZipCode();
This gets worse with deeply nested hierarchies. Although this code is type safe in the sense that it does not violate any CLR rules, it is unsafe in the sense that the developer depends on the details of the type implementation to do the job. It is truly safer than the dynamic equivalent.
dynamic GetAUser() { ... } int zipCode = (int)GetAUser().GetAddress().GetZipCode();
source share