djordan (6) [Avatar] Offline
I'm not sure I follow you in your last bullet point on p 104.

The sublocations list in the implementation is a List<FabulousStorageLocation> and so is also a IEnumerable<FabulousStorageLocation>.

GetSublocations returns IEnumerable<IStorageLocation>. Don't we want the helper method to convert an IEnumerable<TSource> to IEnumerable<TDest> (not IEnumerators) where in this case TSource is FabulousStorageLocation and TDest is IStorageLocation?

jon.skeet (483) [Avatar] Offline
Re: p 104, last bullet point
Hi Dave,

You're right - you would want to convert an IEnumerable<TSource> to an IEnumerable<TDest>. In fact, with iterators you could do this without an explicit helper class, using an iterator block:

public IEnumerable<IStorageLocation> GetSublocations()
foreach (FabulousLocation location in list)
yield return location;

If you *did* write an explicit helper class, you could either use the same trick with iterator blocks, or use *another* helper class which really *did* convert from IEnumerator<TSource> to IEnumerator<TDest>.

I'm hoping to improve this whole section in the second edition - particularly as C# 4 *does* support variance in certain situations.