IEnumerable - Where

S

shapper

Hello,

I created a function the returns an IEnumerable

public static IEnumerable GetMembershipCreateStatus(CultureInfo
culture) {
switch (culture.TwoLetterISOLanguageName.ToLower()) {
case "en":
return new[] {
new { Name = MembershipCreateStatus.DuplicateEmail,
Description = "..." },
new { Name =
MembershipCreateStatus.DuplicateProviderUserKey, Description =
"..." },
};
}
return null;
}

I am trying to use and filter this list as follows:

string error =
Asset.GetMembershipCreateStatus(Thread.CurrentThread.CurrentCulture).Where(s
=> s.Name ==
MembershipCreateStatus.DuplicateEmail).SingleOrDefault().Description;

I get an error:

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

If I use it inside my method Where is recognized:

case "en":
return new[] {
new { Name = MembershipCreateStatus.DuplicateEmail,
Description = "..." },
new { Name =
MembershipCreateStatus.DuplicateProviderUserKey, Description =
"..." },
}.Where(s => s.Name = Input);

What am I doing wrong?

Thanks,

Miguel
 
J

Jon Skeet [C# MVP]

If I use it inside my method Where is recognized:

case "en":
return new[] {
new { Name = MembershipCreateStatus.DuplicateEmail,
Description = "..." },
new { Name =
MembershipCreateStatus.DuplicateProviderUserKey, Description =
"..." },
}.Where(s => s.Name = Input);

What am I doing wrong?

You're trying to use it on the plain nongeneric IEnumerable. Where is
only defined for the generic IEnumerable<T> type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top