I have several classes that all There is no complaint about the compiler T: Error 1 type or namespace name 'T' could not be found (whether you use the Director Are not the assemblies missing the context?) Is there a way to define a list of IWidget and still have a generic interface? I am using .NET 3.5 SP1. 1) You need a non-common route: So that you 2) You can use the 3) or you can match two methods: and you 4) You can go about this in the final way: Which would be useful, if you plan to declare several lists written in, then you should: IWidget & lt; T & gt; Implementing the interface. I would like to add them to the list, so I define something like this:
list & lt; IWidget & lt; T & gt; & Gt; _widgetList;
There are a few ways to do this:
Public interface IWidget {...} Public Interface IWidget & lt; T & gt; : IWidget {...}
list & lt; IWidget & gt; _widgetList;
dynamic s or polymorphism with a coat / co-vibration, but your To play in accordance with the rules of the rules,
& lt; T & gt; should not be a value type and you have to enter after entering, but not when it is added, like this:
IWidget & lt; String & gt; Xxx = ...; Var widgetListDyn = New list & lt; IWidget & lt; Dynamic & gt; & Gt; (); Var widgetListObj = new list & lt; IWidget & lt; Object & gt; & Gt; (); WidgetListDyn.Add (xxx); WidgetListObj.Add (xxx);
Public Interface: IWidget: IWidget & lt; Object & gt; {}
list & lt; IWidget & gt; You can use. _Vidit list; with this technique you
.add () :
list
Public class IWidgetList & lt; T & gt; : List & lt; IWidget & lt; T & gt; & Gt; {}
list & lt; IWidget & lt; TYPE & gt; & Gt; and instead you can use it:
IWidgetList & lt; TYPE & gt; and it's similar
No comments:
Post a Comment