Quantcast
Channel: User Filip Milovanović - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 182

Comment by Filip Milovanović on C#'s Aversion to Array

$
0
0
Prefer IEnumerable<T> for inputs to public methods (more so if they are of wider utility). This gives you more flexibility, as you can theoretically pass in any collection. That is, unless you specifically want to only work with arrays for performance reasons or something. For outputs, it's often fine to return a more concrete type, especially if you are creating a new collection anyway. This plays nicely with input-output variance in polymorphic scenarios (Dog Foo(Animal) can be assigned to Func<Mammal, Mammal> in a type-safe way, assuming Animal > Mammal > Dog inheritance chain).

Viewing all articles
Browse latest Browse all 182

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>