473,395 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Console key example

Does anyone have a simple example on how to use the Console.Key() function?
I’m just trying to read in 5 numbers.
Something like this.

String Key ConsoleKeyInfo();
Int Number =0;
For (int I =0; I<=5; I++)
{ Key = Console.Key();
Number = Number & Convert.ToInt32(Key);
}

--
thank You
Sep 8 '07 #1
1 4109
"Gus Chuch" <Gu******@discussions.microsoft.comwrote in message
news:E4**********************************@microsof t.com...
Does anyone have a simple example on how to use the Console.Key()
function?
I’m just trying to read in 5 numbers.
Something like this.

String Key ConsoleKeyInfo();
Int Number =0;
For (int I =0; I<=5; I++)
{ Key = Console.Key();
Number = Number & Convert.ToInt32(Key);
}

Well, it would help if it was actually C# code. ConsoleKeyInfo is not a
funciton, it is a type:
ConsoleKeyInfo Key;

At the end of the function, you'll wind up with Number equalling the value 0
(because you assigned it 0 at the start and are doing bitwise &. 0 &
number = 0).
What you probably want to do is something like:
List<intNumbers = new List<int>();
.... in the loop:
Numbers.Add(readValue);

There is no function called Key() in the Console class you are probably
looking for ReadKey.

Convert.ToInt32 won't do what you're expecting with the ConsoleKeyInfo
class....

ReadKey reads one key at a time...what if I wanted to input a multidigit
number (like "12")?

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

Sep 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Dom | last post by:
can someone please help me display text in the console cout << "Testing"; in a different colour to the default one
2
by: nick | last post by:
I am using C# do write a console program. Can I do the following tasks: 1. Detect if a key on keyboard is pressed? and get the typed ASC II code? 2. Catch and handle the event of the Control-C?...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
1
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...
19
by: Jeff S | last post by:
Whenever I execute any Console commands (Console.WriteLine "yada yada yada"), the console does not appear. It doesn't even flash by. I want to be able to use Console commands. Any ideas? I'm...
1
by: Kevin | last post by:
In a newsgroup thread from Jan 8, 2003 between Barry Holsinger and the VBDotNet Team, please review this excerpt: "You understood my problem completely. Your sample code provides a really...
6
by: metiu | last post by:
Say I have a console app that does something in three steps: - opens a file - transfers the file through a serial port - does some elaborations and I want to build a GUI around it that, for...
3
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...
12
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...
0
by: Stephen Thomas | last post by:
Hi there I wonder if any one has encountered this problem or can suggest what is wrong. I am trying the a procedure from the msn site but get the following message: Error 1 The type or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.