ReSharper 2017.1 Help

Code Inspection: Parameter type can be IEnumerable<T> (non-private accessibility)

This is a solution-wide code inspection. It only works when the solution-wide analysis is enabled.

If you have a method whose parameter is an array, a List or some other type that implements IEnumerable<T>, ReSharper offers you an option to change the parameter type to IEnumerable<T> — provided that the method itself only iterates the collection and does not access any non-IEnumerable members.

The benefit from this change, if you choose to make it, is that the method becomes agnostic with respect to the type of the collection you pass to it.

Suboptimal codeAfter the quick-fix
public void ViewCategories(IList<string> categories) { foreach (var c in categories) { Console.WriteLine(c); } }
public void ViewCategories(IEnumerable<string> categories) { foreach (var c n categories) { Console.WriteLine(c); } }

See Also

Last modified: 4 July 2017