tags:

views:

75

answers:

3
        var stuff = ctx.spReport();
        var StuffAssembled = new List<ReportCLS>();
        var val = new List<ReportCLS>();
        foreach (var item in stuff)
        {
            StuffAssembled.Add(new ReportCLS(item));

        }

        val.Add(StuffAssembled.First());

Keeps throwing

System.Collections.Generic.List' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)

what is going wrong ?

moreover how do i fix it?

Thanks

+9  A: 

you should add this to your using statements:

using System.Linq;
Philippe Leybaert
That was it ... Intellisense wasnt suggesting I add it either. and I kept seeing (System.Data.Linq) and thought i was good.
Hurricanepkt
+1  A: 

A few things to check:

  • You're targeting .NET 3.5 or higher (or you're using LINQBridge)
  • You have a reference to the System.Core assembly
  • You have a using directive for System.Linq

Basically what the error message suggests...

EDIT: Additionally, your current code could be a lot simpler:

 var stuff = ctx.spReport();
 var stuffAssembled = stuff.Select(x => new ReportCLS(x)).ToList(); 
 var val = new List<ReportCLS> { stuffAssembled.First() };

Also, if you're actually using a List<T> then you might as well just use list[0] instead of list.First() :) Both will throw an exception if the list is empty, although the exception will differ, of course.

Jon Skeet
A: 

This compile-time error usually occurs when you

  • forgot to include imports for LINQ extensions (using System.Linq)
  • forgot to reference assembly with LINQ extensions
  • targeting 2.0 framework, which does not include LINQ by default
Valera Kolupaev