I have always been taught that programming against an interface is better, so parameters on my methods I would set to IList<T> rather than List<T>..
But this means I have to cast to List<T> just to use some methods, one comes to mind is Find for example.
Why is this? Should I continue to program against interfaces, but continue to cast or revert?
I am a little bit confused why Find (for example) isn’t available on the IList<T> which List<T> inherits from.
Personally I would use
IList<T>rather thanList<T>, but then use LINQ (Select,Whereetc) instead of the List-specific methods.Casting to
List<T>removes much of the point of usingIList<T>in the first place – and actually makes it more dangerous, as the implementation may be something other thanList<T>at execution time.