2 Replies
333fred
333fred2y ago
You're not going to like the answers to your questions First: you cannot convert this to T implicitly. It's the definition of unsafe Did you perhaps want to specify IFoo as IFoo<T> where T : IFoo<T>, and then have A implement IFoo<A>? And not have GetInstance be generic at all? Note that, of course, that would mean that you can't specify List<IFoo>, because you don't have a concrete type argument A list of heterogeneous data needs to be checked when trying to access individual elements as specific subtypes of that data You have no way of knowing, given a List<IFoo>, which elements are actually As and which are Bs, and yes you will need to do type tests or specify the type in some fashion to access members specific to A or B on each element
Instinct
InstinctOP2y ago
Gotcha, thanks for the explanation!
Want results from more Discord servers?
Add your server