Alternative implementation: return e.Select(x => (U)x); 2009/2/23 Chris Howie <[email protected]>
> On Mon, Feb 23, 2009 at 8:10 AM, Ricky Clarkson > <[email protected]> wrote: > > Right now I'd use IEnumerable<object> objects = stringList.Select(x => > > (object)x); or if you must have List<>, List<object> objects = > > stringList.Select(x => (object)x).ToList(); > > > > The advantage of the IEnumerable is that no actual copying is done. > > Maybe something like this could be used until C# 4 hits: > > public static IEnumerable<U> Upcast<T, U>(this IEnumerable<T> e) where T : > U { > foreach (T i in e) > yield return i; > } > > IEnumerable<object> e = someStringList.Upcast<string, object>(); > > -- > Chris Howie > http://www.chrishowie.com > http://en.wikipedia.org/wiki/User:Crazycomputers >
_______________________________________________ Mono-list maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-list
