How to get a int or float from the keyboard ?

  • Thread starter Thread starter songjizheng
  • Start date Start date
S

songjizheng

I want to get a variable of int or float in the console .Now can I use this
language below ?
static void Main(string[] args)
{
//
// TODO: ÔÚ´Ë´¦Ìí¼Ó´úÂëÒÔÆô¶¯Ó¦ÓóÌÐò
//
string c=Console.ReadLine();

Console.WriteLine(c);
}
 
songjizheng said:
I want to get a variable of int or float in the console .Now can I use this language below ?
string c=Console.ReadLine();

int n = int.Parse( c); // or, float f = float.Parse( c);
: :
Console.WriteLine(c);

Parse( ) will throw a FormatException if c isn't really a number.


Derek Harmon
 
Back
Top