Read a line from console : Console Input Output : Development Class C# Source Code


Custom Search

C# Source Code » Development Class » Console Input Output »

 

Read a line from console









    

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

// dbTest.cs -- Sample program to be used with cordbg.exe
//
//              Compile this program with the following command line:
//                  C:>csc /debug:full dbTest.cs
//
using System;

namespace nsDebug
{
    public class dbTest
    {
        static public void Main ()
        {
            double x = 7.0;
            while (true)
            {
                Console.Write ("\r\nPlease enter a number: ");
                string str = Console.ReadLine ();
                if (str.Length == 0)
                    break;
                double val = 0;
                try
                {
                    val = Convert.ToDouble (str);
                }
                catch (Exception)
                {
                    Console.WriteLine ("\r\nInvalid number");
                    continue;
                }
                Console.WriteLine (x + " X " + val + " = {0,0:F6}", val / x);
            }
        }
    }
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Development Class
» Console Input Output