score:2

Accepted answer

In .NET 3.5, there exists a static Enumerable existing in System.Linq, which contains extension methods for manipulating IEnumerables - this is not what you want to (or clearly can) return. Change it to IEnumerable, which is the non-generic enumerable class (and what I think you intend), and all should work fine.

Even better, use the generic version of IEnumerable, as such:

public static IEnumerable<StuffDepartman> LoadDataByName(string name)
{
    var stuffs = (List<StuffDepartman>)HttpContext.Current.Session["Stuffs"];

    return (from s in stuffs where s.Name == name select s.Name);
}

Also, note that you don't need the call to AsEnumerable before returning, since List<T> implements IEnumerable<T>, and the former can be implicitly casted to the latter. The = needed to be changed to ==, since you want to use the equality rather than assigment operator here. The other changes are just tidying up.

score:1

System.Linq.Enumerable is a static class with a bunch of extension methods defined on it. You perhaps meant to return IEnumerable<string> instead.

score:0

Enumerable is a static class, what you want to do is return an IEnumerable:

    public static  IEnumerable<string>  LoadDataByName(string name)
    {
      //do stuff
    }

I'm assuming s.Name in your example is a string, which is why the method should return IEnumerable<string>. If it's another type, then change it to that type....

EDIT: Ok, I guess it's not a string. Change it to:

    public static  IEnumerable<StuffDepartman>  LoadDataByName(string name)
    {
      //do stuff
    }

Related Articles