Why do we need iterators in c#?

前端 未结 10 1897
情话喂你
情话喂你 2021-02-05 18:35

Can somebody provide a real life example regarding use of iterators. I tried searching google but was not satisfied with the answers.

10条回答
  •  孤街浪徒
    2021-02-05 19:34

    Iterate through the students in a class

    The Iterator design pattern provides us with a common method of enumerating a list of items or array, while hiding the details of the list's implementation. This provides a cleaner use of the array object and hides unneccessary information from the client, ultimately leading to better code-reuse, enhanced maintainability, and fewer bugs. The iterator pattern can enumerate the list of items regardless of their actual storage type.

提交回复
热议问题