What are iterators?

Answer Posted / srinivas.r

An iterator is a section of code that returns an ordered
sequence of values of the same type.

An iterator can be used as the body of a method, an
operator, or a get accessor.

The iterator code uses the yield return statement to return
each element in turn. yield break ends the iteration. For
more information, see yield.

Multiple iterators can be implemented on a class. Each
iterator must have a unique name just like any class
member, and can be invoked by client code in a foreach
statement as follows: foreach(int x in
SampleClass.Iterator2){}

The return type of an iterator must be IEnumerable,
IEnumerator, IEnumerable<T>, or IEnumerator<T>.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is whitespace in c#?

490


Explain attributes in c#?

477


What does dbml mean?

500


Why cannot you specify the accessibility modifier for methods inside the interface?

491


Can properties be private in c#?

474






What is stringbuilder c#?

507


Is exe is machine dependent?

496


Why attributes are used in c#?

475


What is the output of TextWriterTraceListener redirected?

541


What is the difference between add and addrange in c#?

501


What are assemblies?

539


Give some examples for built in datatypes in c#?

550


Which of these string definitions will prevent escaping on backslashes in c#?

567


What does convert toint32 mean?

505


What is serialization in c#?

474