Results 1 to 4 of 4

Thread: What do you mean by C# Iterators

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    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.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    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.

  4. #4
    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.

Similar Threads

  1. Efficient memory usage with iterators in Python
    By Sivann in forum Software Development
    Replies: 4
    Last Post: 25-10-2010, 01:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,646,886.05061 seconds with 17 queries