How to read char from the console

后端 未结 3 1023
春和景丽
春和景丽 2020-12-03 22:27

I have a char array and I want to assign values from the console. Here\'s my code:

char[] input = new char[n];
for (int i = 0; i < input.Leng         


        
3条回答
  •  悲哀的现实
    2020-12-03 22:54

    Grab the first character of the String being returned by Console.ReadLine()

    char[] input = new char[n];
    for (int i = 0; i < input.Length; i++)
    {
        input[i] = Console.ReadLine()[0];
    }
    

    This will throw away all user input other than the first character.

提交回复
热议问题