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 8112665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:34:47+00:00 2026-06-06T02:34:47+00:00

I have a console application that uses a number of command line switches to

  • 0

I have a console application that uses a number of command line switches to control various methods. Each of the command line switches is handled by a switch statement that is within a for loop that iterates over each of the args.

        for (int x = 0; x < args.Length; x++)
        {
            switch (args[x])
            {
             ...
            }
         }

This works perfectly for my needs, however I need to add a –loop switch that causes the preceding args to be looped indefinitely based upon a timeout period specified by the –set-timeout switch.

The code I have so far is:

switch (args[x])
{
   case "--set-timeout-5m":
       timeout = 300000;
       System.Threading.Thread.Sleep(timeout);
       break;

       ....

    case "--loop":
        x = 0;
        break;
 }

The problem is setting x does not cause the for loop to continue from the start of args. It just sits there.

I am expecting x to have scope as the code is within the for loop and no errors are generated in Visual Studio. I am also expecting the break statement to break the case and pass x to the for loop.

Can anyone explain why it does not work or perhaps post a workaround?

  • 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-06-06T02:34:48+00:00Added an answer on June 6, 2026 at 2:34 am
    for (int x = 0; x < 10; x++)
    {
        Console.Write(x);
        x = 0;
    }
    

    prints

    0 1 1 1 1 1 1 1 1 ...

    because x++ is executed after each iteration.

    If you want it to print

    0 0 0 0 0 0 0 0 0 ...

    you need to change it to

    for (int x = 0; x < 10; x++)
    {
        Console.Write(x);
        x = -1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a little console application that uses s#arp. I can create an
I have written a C# console application that uses the Interop.domino.dll assembly to interact
I have a console application that uses an app.config file however I can't figure
I have a console application that uses NHibernate and ActiveRecord. I am using the
I have a .Net console application that uses a QueryString that connects to a
I have a library and a console application that uses a library. The library
I have an command line that uses arguments, I have no problem with this,
I have a console application that uses a database connection string which is defined
I have a console application that uses QtCore and QtGui. I do not use
I have created a simple c# console application with .net framework 2.0 that uses

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.