Suppose you have the following class:
class Car : IPainting
{
...
}
Then such a function:
void AddCars(IEnumerable<Car> collection)
Then the code snippet looks like this:
Car bmw = new Car();
Car mercedes = new Car();
IPainting a = (IPainting) bmw;
IPainting b = (IPainting) mercedes;
IPainting[] paintings = new IPainting[] {a, b};
AddCars(paintings);
This, of course, does not compile, because the AddCars () method only accepts the Cars collection, but this is what the array of "pictures" is made of.
I know that C # 4.0 is likely to provide you with a solution. Is there any workaround today?
Thanks,
Alberto
source
share