Reputation: 17298
i need Enumarable value from below class but give error
public static Enumerable LoadDataByName(string name)
{
List<StuffDepartman> Stuff = (List<StuffDepartman>)HttpContext.Current.Session["Stuffs"];
var stuffs = from s in Stuff select s;
stuffs = from s in Stuff where s.Name = name select s.Name;
return stuffs.AsEnumerable();
}
But Give me error: System.Linq.Enumerable': static types cannot be used as return types
Upvotes: 2
Views: 2290
Reputation: 147471
In .NET 3.5, there exists a static Enumerable
existing in System.Linq
, which contains extension methods for manipulating IEnumerable
s - 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.
Upvotes: 2
Reputation: 103780
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
}
Upvotes: 0
Reputation: 42182
System.Linq.Enumerable
is a static class with a bunch of extension methods defined on it. You perhaps meant to return IEnumerable<string>
instead.
Upvotes: 1