Lecture thumbnail 0:02 / 1:42 In this section of the course.

We’re going to take a look at the iterator design pattern.

And this is all about how traversal of data structures happens and who exactly allows the traversal

of different data structures.

So the motivation is as follows Iteration or traversal of data structures is a core functionality of

various data structures.

And we have this idea of an iterator, which is a class which actually facilitates the traversal.

Now the iterator does two things.

It keeps a reference to the current element and it knows how to move to a different element and it can

tell us whether there is actually somewhere for us to move or whether we have run out of elements to

iterate.

So the iterator is actually an implicit construct in the sense that if you use enumerable of T, then

the dot net framework actually builds a state machine around all your yield return statements.

And so everything happens automatically.

So in the net framework, unlike C plus plus and other languages, life is very easy because you have

all sorts of built in functionality available to you.

And in this course, or at least in this part of the course, we’re going to take a look at how exactly

the net framework makes the traversal of data structures possible.

So the iterator, the classic definition of an iterator is that it’s an object which facilitates the

traversal of a data structure.

But in the net framework, it doesn’t have to be an object.

It can be a method which returns, for example, an enumerable of T and which operates using yield,

return and yield break statements.

Stop Play Play Play Play Start Play information alert