Home > Net >  How to convert String to Char in C#
How to convert String to Char in C#

Time:10-14

I'm a beginner in C#, I'm trying to make the logic of a hangman game. I have a problem to create the string that will be hidden for the user. I thought I had found the solution with an array of characters. But from what I understand there is a problem between string and char.

The problem itself is located on this part: hiddenWord[i] = "*"; (on the loop) (Cannot implicitly convert type 'string' to 'char')

        // Création du mot secret
    char[] hiddenWord = "".ToCharArray();
    for (int i = 0; i < word.Length; i  )
    {
        hiddenWord[i] = "*";
    }

Thanks for your help !

CodePudding user response:

chars are denoted by single quotes ('), not double quotes ("):

hiddenWord[i] = '*';
// Here --------^-^
  • Related