• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

FIND THE ERROR

AFTER ENTER THE VALUE,I AM PRESSING ENTER,THEN THE CONSOLE IS CLOSING INSTEAD OF  DESPALYING THE VALUE

using System;

namespace ConsoleApplication1
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
      {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main(string[] args)
            {
                  string s;
                  try
                  {
                        Console.WriteLine ("enter the value");
                        s=Console.ReadLine();
                        Console.WriteLine(s);
                        //23222
                        // TODO: Add code to start application here
                        //
                  }
                  catch(Exception e)
                  {
                        e.ToString ();
                  }
                  
            }
      }
}
0
beeravally
Asked:
beeravally
1 Solution
 
stuartdehaanCommented:
Perhaps you should create a shortcut to you program. View properties and un-select the checkbox which says "Close program when finished" or something similar (I have a Dutch WIndows version).
Use the shortcut to launch the program.

It is of course also possible to insert a getchar call; this wait's for user input before returning.

Stuart
0
 
Julian HansenCommented:
There is nothing wrong with the code.

I suspect the problem is that if you are running this in the VS .Net IDE the application is terminating and closing the console window which it does unlike VS 6 where the user had the option to press a key to close the window.

Option 1

put a break point on the Console.WriteLine(s) line by clicking on it and pressing F9
Run the program - the program will break on this line after you enter a value
Make VS .Net the foremost window and press F10.
Alt Tab back to the console window - you will see your value out put.

Option 2

Find the exe generated during the compile
Open a cmd shell and cd to the folder where the exe is - run it from the cmd shell

Option 3

Put a "pause" statement after the WrteLine - example another ReadLine.

That should do it
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now