Using IReadOnlyCollection instead of IEnumerable for parameters to avoid possible multiple enumeration

后端 未结 1 1741
执念已碎
执念已碎 2021-01-11 12:21

My question is related to this one concerning the use of IEnumerable vs IReadOnlyCollection.

I too have always used

相关标签:
1条回答
  • 2021-01-11 13:10

    Having thought about this further, I have come to the conclusion, based on the article I mentioned in my Question, that it is indeed OK to use IReadOnlyCollection<T> as a parameter, but only in functions where it will definitely be enumerated. If enumeration is conditional based on other parameters, object state, or workflow, then it should still be passed in as IEnumerable<T> so that lazy evaluation is semantically ensured.

    0 讨论(0)
提交回复
热议问题