.net - Mixture of types in generic list -


I am trying to do the following:

  list & lt; IRepository & lt; IBusinessObject, ICriteria & gt; & Gt; Repositories {receive; }  

and call it

  IRAPSorporation & lt; ICustomer, ICustomerCriteria & gt; CR = new customer repository (); List.Add (CustomerRepository);  

Where ICustomer and ICustomerCriteria descend from IBusinessObject and ICriteria, respectively.

However, the compiler does not like it.

Hmmm, I know I'm pushing it a bit, but I thought it would work? Anyone know why?

Thanks Duncan

This is a problem:

This will clarify the problem:

  list & lt; String & gt; Wire = ...; & Lt; Object & gt; Object = strings; // Objects.Add (42); // 42 is an object - should work // But we will add an integer to the list of strings !!  

In .NET FX 4, C # to allow a specific type of these and outside normal behavior to correct behavior Will support.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -