Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to continue without exiting...

How to continue without exiting...

Scheduled Pinned Locked Moved C#
questiondatabasexmltutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tash18
    wrote on last edited by
    #1

    Hi guys.. I have developed a console application that migrates data present in xml file to my database.. my console application asks the app name from the user and based on the name entered by the user the application migrates only those records corresponding to that app name.. Now my question is after the migration is done my console application exits.. but i dont want it to exit, instead it must ask the user whether to exit if the user enters "exit" then it must exit otherwise the console application should repeat its migration process from the beginning and ask the user the app name and so on it goes... how do i implement this logic??? Thanx in advance.. Regards, Tash

    L H 2 Replies Last reply
    0
    • T Tash18

      Hi guys.. I have developed a console application that migrates data present in xml file to my database.. my console application asks the app name from the user and based on the name entered by the user the application migrates only those records corresponding to that app name.. Now my question is after the migration is done my console application exits.. but i dont want it to exit, instead it must ask the user whether to exit if the user enters "exit" then it must exit otherwise the console application should repeat its migration process from the beginning and ask the user the app name and so on it goes... how do i implement this logic??? Thanx in advance.. Regards, Tash

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      bool isExit = false;
      while(!isExit)
      {
      //ask name here...
      //...

      //ask exit here
      Console.WriteLine("Do you want to exit ?");
      string answer = Console.ReadLine();
      if(answer == "exit")
      {
      isExit = true;
      }
      }

      T 1 Reply Last reply
      0
      • T Tash18

        Hi guys.. I have developed a console application that migrates data present in xml file to my database.. my console application asks the app name from the user and based on the name entered by the user the application migrates only those records corresponding to that app name.. Now my question is after the migration is done my console application exits.. but i dont want it to exit, instead it must ask the user whether to exit if the user enters "exit" then it must exit otherwise the console application should repeat its migration process from the beginning and ask the user the app name and so on it goes... how do i implement this logic??? Thanx in advance.. Regards, Tash

        H Offline
        H Offline
        Harvey Saayman
        wrote on last edited by
        #3

        Hey there Thashif I'd use a while loop for that :) Here's an example

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;

        namespace ConsoleTest
        {
        class Program
        {
        static void Main(string[] args)
        {
        bool QuitProgram = false;

                while (!QuitProgram)
                {
                    Console.WriteLine("Please type your name or \\"quit\\" to exit");
        
                    string Response = Console.ReadLine();
        
                    if (Response.ToLower() == "quit")
                    {
                        QuitProgram = true;
                    }
                    else
                    {
                        DoWork(Response);
                    }
                }
            }
        
            public static void DoWork(string Response)
            {
                Console.WriteLine("Hello {0}", Response);
            }
        }
        

        }

        Hope this helps :)

        Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

        T 1 Reply Last reply
        0
        • H Harvey Saayman

          Hey there Thashif I'd use a while loop for that :) Here's an example

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;

          namespace ConsoleTest
          {
          class Program
          {
          static void Main(string[] args)
          {
          bool QuitProgram = false;

                  while (!QuitProgram)
                  {
                      Console.WriteLine("Please type your name or \\"quit\\" to exit");
          
                      string Response = Console.ReadLine();
          
                      if (Response.ToLower() == "quit")
                      {
                          QuitProgram = true;
                      }
                      else
                      {
                          DoWork(Response);
                      }
                  }
              }
          
              public static void DoWork(string Response)
              {
                  Console.WriteLine("Hello {0}", Response);
              }
          }
          

          }

          Hope this helps :)

          Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

          T Offline
          T Offline
          Tash18
          wrote on last edited by
          #4

          Thanx alot.. ur code helped me alot... Million thanx Regards, Tash

          H 1 Reply Last reply
          0
          • L Lost User

            bool isExit = false;
            while(!isExit)
            {
            //ask name here...
            //...

            //ask exit here
            Console.WriteLine("Do you want to exit ?");
            string answer = Console.ReadLine();
            if(answer == "exit")
            {
            isExit = true;
            }
            }

            T Offline
            T Offline
            Tash18
            wrote on last edited by
            #5

            Thanx it worked fine... Regards, Tash

            1 Reply Last reply
            0
            • T Tash18

              Thanx alot.. ur code helped me alot... Million thanx Regards, Tash

              H Offline
              H Offline
              Harvey Saayman
              wrote on last edited by
              #6

              Your welcome :) PS: Please don't forget to mark the post good answer :thumbsup:

              Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups