I have a method that takes a collection of type float as an argument. Most of the time a ReadOnlyCollection<float> is passed to the method but sometimes different types of collections like a List are also passed.
What would be the best type for the parameter? Should I use: public void MyMethod(Collection<float>)? Is it good practice?
It depends on what you are doing with the collection.
If you just want to enumerate over it, pass in
IEnumerable<float>. If you need to also add/remove items, useICollection<float>. If you need to access by index, useIList<float>.From your description of the different types, you do not need to add items, so
IEnumerable<float>should be fine.In general, use the most general type you can (interface over implementation, something with less methods than one with more). See the Liskov substitution principle (the L in the SOLID design principles).