Possible Duplicate:
Is it possible to recreate this statement without using a foreach?
I have 2 classes that share a base class
DealBookmarkWrapper : BookmarkWrapper
StoreBookmarkWrapper : BookmarkWrapper
I also have the following statements:
// 1 - This works
List<BookmarkWrapper> bm = new List<BookmarkWrapper>();
foreach(var d in deals)
{
bm.Add(new DealBookmarkWrapper(d));
}
// 2 - This does not work
List<BookmarkWrapper> bm2 = deals.Select(d => new DealBookmarkWrapper(d)).ToList();
1) Works as it but 2 needs a cast to work. I'm unsure whether I'm doing something wrong or if a cast is genuinely required in the second scenario.
Anyone throw some light on it?