I know there has been a lot of posts on this but it still confuses me why should you pass in an interface like IList and return an interface like IList back instead of the c
Inside the method, you should use var
, instead of IList
or List
. When your data source changes to come from a method instead, your onlySomeInts
method will survive.
The reason to use IList
instead of List
as parameters, is because many things implement IList
(List and [], as two examples), but only one thing implements List
. It's more flexible to code to the interface.
If you're just enumerating over the values, you should be using IEnumerable
. Every type of datatype that can hold more than one value implements IEnumerable
(or should) and makes your method hugely flexible.