【发布时间】:2014-06-13 16:34:18
【问题描述】:
我正在使用 Resharper 获得一个 IEnumerable 的可能多重枚举,我正试图找出它是否真的是一个问题。这是我的方法:
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" }
}
}
应该很明显,但我正在搜索Contact,如果搜索未返回任何结果,我将返回一组默认值。消费者应该只收到一个可以枚举而不是修改的列表。
这里的“多重枚举”在哪里?如果确实有一个,这不是在这种情况下使用的最佳类型吗?
【问题讨论】:
标签: c#