Re: long input
From: Branimir Giurov (branimir_at_nospam.com)
Date: 08/27/04
- Next message: Hin: "protected internal"
- Previous message: cyrille: "Re: ToolTips on ListView Header"
- In reply to: Dave: "long input"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 27 Aug 2004 10:44:13 +0300
Hi there,
you should save user's input as a string, then either try to parse it with
long.Parse(string) or first validate the string (with RegEx for example) and
then parse it if the string's valid input for a long value. If by any chance
the conversion doesn't work, you'll recive a FormatException, so it might be
a good idea to catch it. Something like the following:
long getInput()
{
while ( true )
{
string input = Console.ReadLine();
try
{
long value = long.Parse(input);
return value;
}
catch ( FormatException )
{
Console.WriteLine("Invalid input. Please enter a valid long value");
}
}
}
Cheers,
Branimir
-- Branimir Giurov MCSD.NET, MCDBA www.sofiadev.org "Dave" <better_cs_now@yahoo.com> wrote in message news:10iteqt5gia542e@news.supernews.com... > > What's the proper way to get a long from the console? > >
- Next message: Hin: "protected internal"
- Previous message: cyrille: "Re: ToolTips on ListView Header"
- In reply to: Dave: "long input"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|