Click here to Skip to main content
15,881,092 members

Convert Console.Key to string! Need help (very basic stuff C# console)

Joel Whatley- asked:

Open original thread
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static Random newletter = new Random();
        static void Main(string[] args)
        {
            
            string[] alphabet;
            Console.WriteLine("Typing reflex game"); Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("You must type the letter you see as fast as you can");
            Console.WriteLine("Hit enter to start");
            Console.ReadLine();
            Console.WriteLine("The game starts in: 3"); System.Threading.Thread.Sleep(1000);
            Console.WriteLine("The game starts in: 2"); System.Threading.Thread.Sleep(1000);
            Console.WriteLine("The game starts in: 1"); System.Threading.Thread.Sleep(1000);
            ConsoleKeyInfo inputletter; 
            alphabet = new string[26];
            alphabet[0] = "A";
            alphabet[1] = "B";
            alphabet[2] = "C";
            alphabet[3] = "D";
            alphabet[4] = "E";
            alphabet[5] = "F";
            alphabet[6] = "G";
            alphabet[7] = "H";
            alphabet[8] = "I";
            alphabet[9] = "J";
            alphabet[10] = "K";
            alphabet[11] = "L";
            alphabet[12] = "M";
            alphabet[13] = "N";
            alphabet[14] = "O";
            alphabet[15] = "P";
            alphabet[16] = "Q";
            alphabet[17] = "R";
            alphabet[18] = "S";
            alphabet[19] = "T";
            alphabet[20] = "U";
            alphabet[21] = "V";
            alphabet[22] = "W";
            alphabet[23] = "X";
            alphabet[24] = "Y";
            alphabet[25] = "Z";
            do
            {
                Console.Clear();
                int lol = newletter.Next(0, 25);
                Console.WriteLine("Typing reflex game"); Console.WriteLine(); Console.WriteLine();
                Console.WriteLine("                     TYPE THIS LETTER:"); Console.WriteLine();
                Console.Write("                              "+ alphabet[lol]);
                inputletter = Console.ReadKey();
                inputletter = Convert.ToString;
                alphabet[lol].ToString();
                if (inputletter == alphabet[lol])
                {
                   // Add a point, or something
                }
                Console.WriteLine(inputletter.Key.ToString());
             } while (inputletter.Key != ConsoleKey.Escape);
            
            
        }
    }
}


This part:

C#
inputletter = Console.ReadKey();
                inputletter = Convert.ToString;
                alphabet[lol].ToString();
                if (inputletter == alphabet[lol])
                {
                }


I'm practicing for college work and I'm trying to make a app where the user types in the letter shown then it shows how many they got correct out of how ever many attempted (and I will try put in a timer system). I don't know how to make it check if the inputletter (the key input when the letter is shown) is equal to the alphabet[lol] (being a random chosen letter in the alphabet array)

please help :(
and any other help would be greatly appreciated
- first time using this site

I get 2 errors:
Cannot convert method group ToString to non-delegate type System.ConsoleKeyInfo. Did you intend to invoke the method?

and:
Operator == cannot be applied to operands of type System.ConsoleKeyInfo and string
Tags: C#, String, Convert, Console

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900