c# - Access to an inner type -
A colleague of mine posted a question on an internal forum that I was thinking about via C # This is possible from. Basically, he has got the interface:
Public Interface IPO Finder & lt; T & gt; {T GetT (); }
Is it possible to use a thing that implements an interface as another normal type of type parameter and has access to Type T without re-specifying it? For example:
public squares foo & lt; P & gt; Where P: The IPOounder & lt; T & gt; {P.P. T GetInnerT () {Return p. GETT (); }}
It does not compile, because type is not defined TYPE and therefore can not be used as the parameter of IProvider
. Is anything like that possible? Just curious!
No, it will need to be Foo
to be in general both p and T:
public class Foo < P, T & gt; Where P: The IPOounder & lt; T & gt;
Otherwise no T
for IProvider & lt; T & gt; Obligations to be aware of - The fact is that this is part of the announcement
IProvider & lt; T & gt;
is a coincidence. In T
in T
in T
the IProvider & lt; T & gt;
(from the viewpoint of the compiler). For example, this would be an equivalent declaration:
public square fu & lt; TProvider, TProvided & gt; Where TProvider: IProvider & lt; TProvided & gt;
One more thing to keep in mind is that the IPOoundinders < T & gt; The implementation of
can execute it several times for different types of arguments:
public class Big Provider: IPOounder & lt; String & gt ;, ipoverinder & lt; Int & gt;, IPOounder & lt; Four & gt;
Now foo < BigPeverder & gt;
What will happen? It will be unclear ... while with my announcement given above, you will:
var x = new Foo & lt; Bigprovider, int & gt; (); There is an intrinsic aspect of to bigprovider
.
Comments
Post a Comment