Skip to main content

Posts

Showing posts with the label iterator

Iterator in csharp

Iterator What is iterator? Iterator is a method or function implementation which implements the iterative features for objects and its return type must be IEnumerable type. We can implement iterators in C# read-only property also (only with get ) In each iteration this method or properties returns one element with the help of Yield return statement What is yield Yield is a keyword which is introduced in Csharp and VB.Net to implement iterator .yield is working like return statement in functions but it will call more than one time like loop. yield gives enumeration properties implicitly for object(i.e means explicitly no need to implement IEnumerator) . Yield was implemented in C-sharp and vb.net with different keyword Yield return <expression>; in C# We used yield return statement in iterator to return each element Example static void Main( string [] args)          {             foreach ( var item in getno())