Hi lads, what are the benefits of using base types in method parameters?
Here's one sample:
private void Foo(List<int> numbers) //R# laments: parameter can be IEnumerable.
{
foreach (var i in numbers) {
Console.WriteLine(i);
}
}
And here's another one
public class Foo : ICloneable
{
public object Clone()
{
return MemberwiseClone();
}
public Foo CopyMe(Foo other) //R# laments: parameter can be ICloneable
{
return (Foo)other.Clone();
}
}
...where we can change the type and anything but Foo will fail at runtime.
So the question: what should I do when R# suggests parameter can be of type 'X'?
PS. Just another explanation for Whysharper - a plugin that dovetails Resharper and StackOverflow. People say it's nice but lacks good explanations - hopefully together we can make it better ;).