I am wondering if there is any difference between these two methods. Second one look more natural, but that shouldn't be the only reason to use it. Maybe there are some performance issues or some diabolic mambojambo related to any of them?
void FirstMethod<T>(T a) where T : IEnumerable<Animal>
{
...
}
void SecondMethod<T>(IEnumerable<T> a) where T : Animal
{
...
}
The difference is that you can easily pass IEnumerable<Dog>
to the second method,
but when you pass it to the first method it'll just be implicitly converted to an IEnumerable<Animal>
Take a look at the fiddle
Edited Thanks @Servy for comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With