Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-11-2009
Member
 
Join Date: Nov 2009
Posts: 62
What do you mean by C# Iterators

I am not at all good at programming. Although I have used Visual Basics earlier, but learning Csharp is not at all easy for me. Csharp has many new concepts. Yesterday I read about Iterators in Csharp. I want to know what exactly do you mean by Csharp Iterators. What is their use ? Give an example for it.
Reply With Quote
  #2  
Old 10-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: What do you mean by C# Iterators

C# introduced a new concept called Iterators in C# 2.0. An Iterator in C# can be used as the body of a method, an operator, or a get accessor. The Iterator code in C# makes use of the yield return statement to return each element in turn. yield break statement ends the iteration. In other words, in simple programming language an Iterator can be defined as an object which permits a programmer to traverse through all the elements of a collection, regardless of its specific implementation.
Reply With Quote
  #3  
Old 10-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: What do you mean by C# Iterators

Use of Explicit version of Iterators:

Code:
IEnumerator<MyType> i = list.GetEnumerator();
while (i.MoveNext())
    Console.WriteLine(i.Current);

Use of Implicit version of Iterators:

Code:
foreach (MyType value in list)
    Console.WriteLine(value);
An iterator in Csharp is a section of code that returns an ordered sequence of values of the same type.
Reply With Quote
  #4  
Old 10-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: What do you mean by C# Iterators

C# is a programming language which has brought through many new concepts for designing programs for .Net framework. Iterators are introduced in C# 2.0. An Iterator in simple term can be said to be a piece of code which returns an ordered sequence of values. By using Iterators it is no longer needed to omlement the System.Collections.IEnumerable and System.Collections.IEnumerator interfaces while creating a collection of class which provides support to foreach. This work belongs to the compiler. The return type for an Iterator is IEnumerable, IEnumerator, IEnumerable, or IEnumerator.rom the Microsoft Platform SDK, Start WinDbg from the Debug menu, click 'Attach to A Process', select the correct Process ID (PID). If your Web application was running on the same memory space as InetInfo, select Inetinfo.exe from the Process List. From the Debug menu, click Exceptions and then double-click Access Violation, select Action = 'Enabled' and then click on OK. Create the Access Violation by connecting to the Web site. A dialog box will prompt you for the source code. Locate the source code and then select either the .cls document or the .cpp file. The WinDbg debugger should now open another window, showing the line on which the component access violated highlighted on yellow.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What do you mean by C# Iterators"
Thread Thread Starter Forum Replies Last Post
Efficient memory usage with iterators in Python Sivann Software Development 4 25-10-2010 01:53 PM


All times are GMT +5.5. The time now is 03:28 AM.