Tag Collections
IEnumerable vs IReadOnlyList
I apologize to everyone who’s waiting for my response to their code review requests. I was busy dealing with some personal stuff the last couple of weeks. Moving forward, I’m going to maintain a one post a week schedule where "regular" articles would take turns with code reviews. This article is a regular one, so the one next week would be a code review.
Today, I’d like to talk about IEnumerable and IReadOnlyList collection interfaces. We’ll discuss which of them is preferable and in what circumstance.
Return the most specific type, accept the most generic type
I guess most developers heard the guideline stating that, when designing methods, you should return the most specific type and accept the most generic one. Is it always applicable? Let’s try to look at it from different perspectives.
IEnumerable interface in .NET and LSP
I often see developers saying that in most cases, use of IEnumerable breaks LSP. Does it? Let’s find out. This is the continuation of my article Read-Only Collections and LSP. It this post, I’d like to discuss IEnumerable interface from a Liskov Substitution Principle (LSP) perspective. Liskov Substitution Principle and IEnumerable interface To answer the question whether or not use of IEnumerable breaks LSP, we should step back and see what it means to break LSP.