asri.chejarla

Reasons for casting among Interfaces

Discussion created by asri.chejarla on Oct 27, 2012
Latest reply on Oct 31, 2012 by asri.chejarla
Hi all,

One reason why we do casting among the interfaces is to use the members of the interface in question without instantiating it. As in below ex:   (IDocument is not instantiated)

IApplication app;
IMxDocument mDoc = new MxDocumentClass();
app = (mDoc as IDocument).Parent;

Here we are not instantiating IDocument but are able to access its members as and when required on casting.
We could have written the above code in the below lines as well but that would take two interface instantiation (IMxDocument & IDocument)

IApplication app;
IDocument doc = new MxDocumentClass();
app =doc.Parent;
and then IMxDocument instantiation if required.


I would like to know different other reasons why we do casting among interfaces with such examples.


Thanks

Outcomes