I'm getting a Possible multiple enumeration of IEnumerable with Resharper and I'm trying to find out if it's really an issue or not. This is my method:
public IEnumerable<Contact> GetContacts(IContactManager contactManager, string query)
{
IEnumerable<Contact> contacts = contactManager.GetContacts(query);
if (contacts.Any()) return contacts; // Get the warning on this line
// Do some other stuff
return new[] {
new Contact { Name = "Example" }
}
}
Should be obvious, but I'm doing a search for Contact
and if the search returns no results I'm returning an array of default values. The consumer should just receive a list which can be enumerated, not modified.
Where is the "multiple enumeration" here? And if there is indeed one, is this not the best type to use in the situation?