Immer Fehler: 'System.Sammlungen.Generisches.IEnumerable<AnonymousType#1>' enthält keine definition für 'ToList'

Mache ich das unter

List<A> lstA = new List<A>();
            Enumerable.Range(1, 10).ToList().ForEach(i => lstA.Add(new A { Prop1 = i, Prop2 = "Prop2" + i.ToString() }));

            List<B> lstB = new List<B>();
            Enumerable.Range(1, 10).ToList().ForEach(i => lstB.Add(new B { Prop1 = i, Prop3 = DateTime.Now }));

            var res = (from a in lstA
                       join b in lstB on a.Prop1 equals b.Prop1
                       select new
                       {
                           Prop1 = a.Prop1
                           ,
                           Prop2 = a.Prop2
                           ,
                           Prop3 = b.Prop3
                       }).ToList<C>();

Bedeutet das kombinierte Ergebnis speichern möchten, in der Liste.

Damals immer die Fehler

'System.Collections.Generic.IEnumerable<AnonymousType#1>' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments

Wie dies zu tun?

class A
    {
        public int Prop1 { get; set; }
        public string Prop2 { get; set; }
    }

    class B
    {
        public int Prop1 { get; set; }
        public DateTime Prop3 { get; set; }        
    }

    class C
    {
        public int Prop1 { get; set; }
        public string Prop2 { get; set; }
        public DateTime Prop3 { get; set; }
    }

Dank

InformationsquelleAutor user1025901 | 2011-12-09
Schreibe einen Kommentar