IEnumerable - Where

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
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.
 
Back
Top