IList and IReadOnlyList

后端 未结 4 1964
小鲜肉
小鲜肉 2021-02-01 02:20

If I have a method that requires a parameter that,

  • Has a Count property
  • Has an integer indexer (get-only)

What should the type

4条回答
  •  天涯浪人
    2021-02-01 02:24

    What you need is the IReadOnlyCollection available in .Net 4.5 which is essentially an IEnumerable which has Count as the property but if you need indexing as well then you need IReadOnlyList which would also give an indexer.

    I don't know about you but I think this interface is a must have that had been missing for a very long time.

提交回复
热议问题