Identifier Expected?

When I run this code I keep getting “Identifier Expected” at line 16 (I AM VERY NEW TO CODING BTW)

code snippet
  public static void Main(string[] args) 
  {
    string str = "The quick brown fox jumps over the lazy dog.";
    string Typed = "";
    int idx = 1;
    Console.WriteLine(str);
    while (Typed != str)
    {
      char Letter = str[idx];
      if (Console.ReadKey().Key == ConsoleKey.(Letter))
      {
        Typed = Typed + Letter;
        Console.WriteLine(Typed);
      }
    }
  }

I am trying to make it so if you press the letter next in the sentence, it will print what you have typed so far, but I won’t work.

Hi there, I’d suggest using the KeyChar attribute, rather than Key, because then you can change your if condition to Console.ReadKey().KeyChar == Letter.

p.s. strings start at index 0, so set your idx at 0 rather than 1

1 Like

Thanks! Also, i know about the index numbering, I just hadn’t changed it at the time so yeah…

1 Like