Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 940147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:54:26+00:00 2026-05-15T21:54:26+00:00

UPD. Hello, I know how code below is working. I know that cross, and

  • 0

UPD.
Hello,
I know how code below is working. I know that cross, and circle are pointing to Cross(), and Circle() method. But I am still filling little confuse with this part of code. Can you explain it for me?

public GameMoves()
            {
                cross = Cross();
                circle = Circle();
            }

All code

 static void Main(string[] args)
            {
                GameMoves game = new GameMoves();
                IEnumerator enumerator = game.Cross();
                while (enumerator.MoveNext())
                {
                    enumerator = (IEnumerator)enumerator.Current;
                }
            }
        }

        public class GameMoves
        {
            private IEnumerator cross;
            private IEnumerator circle;

            public GameMoves()
            {
                cross = Cross();
                circle = Circle();
            }

            private int move = 0;
            public IEnumerator Cross()
            {
                while (true)
                {
                    Console.WriteLine("X, step {0}", move);
                    move++;
                    if (move > 9)
                        yield break;
                    yield return circle;
                }
            }

            public IEnumerator Circle()
            {
                while (true)
                {
                    Console.WriteLine("O, step {0}", move);
                    move++;
                    if (move > 9)
                        yield break;
                    yield return cross;
                }
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:54:27+00:00Added an answer on May 15, 2026 at 9:54 pm

    Both Cross and Circle are generators. They return a sequence of objects by means of an IEnumerable. That is, you could write:

    foreach (var cross in Cross())  // works with Circle, also
    {
        // ...
    }
    

    And on every loop iteration, the next element to be returned is generated inside the Cross or Circle method. Those methods don’t execute all at a time, instead each time a yield return statement is reached, program execution will continue in the calling code (the foreach loop), and the code inside the generator is only resumed when the next item is needed.


    P.S.: Before my internet connection broke down for some hours, I had also wanted to comment on the strange fact that your generators keeps returning references to themselves via yield return. That doesn’t really make sense to me, to be honest; I’ve never seen that kind of code and I wonder if it actually does something useful?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below code which is working fine: success: function (upd_rsp){ //if email
I working on some applications that route tcp and upd traffic through multiple machines
I tried $(:input:not(input[type=button],input[type=submit],button):visible:first) but it doesn't find anything. What is my mistake? UPD: I
I have such jquery code: $(.quantity).blur(function() { console.log(upd); $.ajax({ url: /line_items/update_quantity/, type: GET, data:
I am writing a Com server and I have wrote code that detect situation
For example, PHP code: $test = hello; ${$test} = $test; echo $hello; // return
UPD: The code works just fine on a newer Redis module version: 1.904 vs
There is a server that sends UPD stream - 60 packets per second I
Where is Python's sys.path initialized from? UPD : Python is adding some paths before
I need to upload files to iDisk drive. I've found that iDisk has webdav

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.