using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LearningKeys
{
class Program
{
static void Main(string[] args)
{
while (true)
{
ConsoleKeyInfo Menu;
Menu = Console.ReadKey(true);
Console.WriteLine("1. Pick Item");
Console.WriteLine("2. Display all Items");
Console.WriteLine("3. Pick Special Item");
Console.WriteLine("4. Quit");
if (Menu.Key == ConsoleKey.Backspace)
{
Console.WriteLine("1. Pick Item");
Console.WriteLine("2. Display all Items");
Console.WriteLine("3. Pick Special Item");
Console.WriteLine("4. Quit");
}
ConsoleKeyInfo DisplayAllItems;
DisplayAllItems = Console.ReadKey(true);
if (DisplayAllItems.Key == ConsoleKey.D1)
{
Console.WriteLine("1. Mushrooms \n2. Sword \n3.Boots");
}
Console.Read();
break;
}
}
}
}
Hello there, I was wondering why my top 4 Console.WriteLine’s disappear when I put the ConsoleKeyInfo variable on top of it. Or why the program does not work when I have more than one Consolekey assigned? I’m sure it is because of the Console.ReadKey(); but I’m not sure of what else to use. I’m just learning ConsoleKeys.
Console.ReadKey is blocking meaning the program will hang until you press a key. You are not seeing the writelines because the program is waiting for a key
It has nothing to do with how many ConsoleKeyInfo variables you have.