Sorry for very silly question.
But, how can I input an integer from keyboard in C# Console
applications?
Like this, in C++ code:
"int i ; cin >i ;"
I just read some tutorials about C#, and I can get a "string" from
keyboard, but I can't get an integer.
Thank you in advance. 7 14873
Adrián E. Córdoba wrote:
But, how can I input an integer from keyboard in C# Console
applications?
Like this, in C++ code:
"int i ; cin >i ;"
I just read some tutorials about C#, and I can get a "string" from
keyboard, but I can't get an integer.
int v = int.Parse(Console.ReadLine());
was at least one way.
Arne
Arne:
Thank you very much.
Arne Vajhøj wrote:
Adrián E. Córdoba wrote:
But, how can I input an integer from keyboard in C# Console
applications?
Like this, in C++ code:
"int i ; cin >i ;"
I just read some tutorials about C#, and I can get a "string" from
keyboard, but I can't get an integer.
int v = int.Parse(Console.ReadLine());
was at least one way.
Arne
Hi,
quick , dirty code :)
int i=0;
while( true )
{
try {
i = Convert.ToInt32( Console.ReadLine() );
break;
}catch{
Console.WriteLine( "Invalid number");
}
}
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Adrián E. Córdoba" <so***********@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
Sorry for very silly question.
But, how can I input an integer from keyboard in C# Console
applications?
Like this, in C++ code:
"int i ; cin >i ;"
I just read some tutorials about C#, and I can get a "string" from
keyboard, but I can't get an integer.
Thank you in advance.
Hi,
"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:WfZNg.37822$_q4.2339@dukeread09...
Adrián E. Córdoba wrote:
>But, how can I input an integer from keyboard in C# Console applications? Like this, in C++ code: "int i ; cin >i ;" I just read some tutorials about C#, and I can get a "string" from keyboard, but I can't get an integer.
int v = int.Parse(Console.ReadLine());
You may get an exception if what you read is not a number
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Ignacio Machin ( .NET/ C# MVP ) wrote:
"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
>int v = int.Parse(Console.ReadLine());
You may get an exception if what you read is not a number
Yep.
The original poster should catch the exception and
so something appropriate if that happen.
Arne
For your information:
I found in a tutorial, a compact expression for Integer input:
int i = Convert.ToInt32(Console.ReadLine());
Thank you again.
Best regards.
--
Adrián
Adrián E. Córdoba wrote:
For your information:
I found in a tutorial, a compact expression for Integer input:
int i = Convert.ToInt32(Console.ReadLine());
To quote from docs for Convert.ToInt32:
Remarks
The return value is the result of invoking the Int32.Parse method on value.
Arne This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Scott Shaw |
last post by:
Hi all,
I was wondering if you could help out with this problem that I am having.
What I am trying to do is detect keyboard input in a while loop without
halting/pausing the loop until the key is...
|
by: Bill Cohagan |
last post by:
I'm writing a console app (in C#) and I want to be able to redirect the
standard input/output streams when it's run at a command prompt. IOW I want
to support the "<" and ">" redirection syntax....
|
by: Mahmood Ahmad |
last post by:
Hi,
I am getting the error 'Input String was not in correct format' in the
following C# program (indicated line):
using System;
namespace CF7
{
class CalcArea
{
|
by: Teis Draiby |
last post by:
I am working on a Win32 program with an additional console window to output
messages. I also want to type commands in the console window. Is there any
common way to achieve that?
For example how...
|
by: JM |
last post by:
Hi,
I need a function for a character based program (console) that works exactly
like the INKEY$() function in (old) QBasic: Read only 1 keystroke and then
move on. Console.Read;...
|
by: julianmoors |
last post by:
Hey,
Currently I'm writing a VB.NET/1.1 app and I need to mask the input for
the password field. Does anyone know how to do this in VB? I've seen a
C# example, but wouldn't know how to convert...
|
by: gopal |
last post by:
Hi,
I am developing a console application and i would like to get userinput
for
Database User & Password.
The Password should be input as **********
Please can some help me out on this?
|
by: fatimahtaher |
last post by:
Hi,
I am supposed to create a program that generates a random number and then asks the user to guess the number (1-100). The program tells the user if he guessed too high or too low. If he...
|
by: Dilip |
last post by:
Hi All
I have a server based C# console application. This application must
hide its console window when its launched out on the field. So I
dutifully P/Invoke'd FindWindow/ShowWindow...
|
by: jane007 |
last post by:
Hello everybody:
I am having a problem.
On Unix platform, there is a script that need user to input data from console, then when I call Unix perl script from
Windows, these is an issue occurs,...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |