DevPinoy.org
A Filipino Developers Community
ATTENTION:Take our Code Challenge for the month of October 2008 and win some great prize! Learn more about it here!

Array of Interfaces

I have this custom layout logic for a custom container control which uses a number of properties defined on an interface implemented by most of our controls.  For this implementation, I needed temporary holders of controls which implement the said interface and the need for an array of the said interface arrives.

I don’t know if this is possible so I immediately googled the idea and found a number of posts by Jon Skeet which says it is possible.  Upon coding, I wonder why I can’t instantiate an array of interface just like he suggested here.

[code language="C#"]
ILayout[] controls = new ILayout[controlCollectionCount]
[/code]

No matter what I do, Intellisense won’t allow me to instantiate an array of interface.  I resorted to use an array of Control class to hold them although I’m aware of the overhead of boxing/unboxing when accessing the properties through the interface.  I tried to use the System.Windows.Forms.Control.ControlCollection class but it has internal logic dependence on its owner supplied in its only constructor which is a hindrance to my purpose.

This morning, I tried to google again and found another post of Mr. Skeet on the idea here.  Intellisense will prevent you to instantiate an array of interface but it is allowable.  Now I have to revise my implementation, :p.

Posted Mar 04 2005, 01:01 PM by jokiz
Filed under: , , , ,

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:

Copyright DevPinoy 2005-2008
Powered by Community Server (Commercial Edition), by Telligent Systems