none
Cannot Implicitly Convert type 'string' to 'char'

    Question

  • I've hit a wall with my code and cannot seem to figure out how to fix this error. Any suggestions would be greatly appreciated.

                char letter1 = "J";
                char letter2 = "U";
                char letter3 = "N";
                char letter4 = "E";

                Console.WriteLine("Welcome to the guessing game! ");
                Console.WriteLine();
                Console.WriteLine("Let the game begin! ");
                Console.WriteLine("Take a guess at the month I was born by entering letters below! ");
                Console.Write("Enter your first guess letter please: ");

    Friday, March 31, 2017 2:03 PM

All replies

  • Use simple quotes :

     char letter1 = 'J';

    Friday, March 31, 2017 2:42 PM
  • Character literal is specified using single quotes while string is using double quotes, either change the char to string while defining variable or use single quotes if you want to stick with char type.

    So, either write:

    char ch = 'A';

    or:

    string ch = "A";

    Hope it helps!


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites


    Friday, March 31, 2017 2:47 PM
  • Try this too:

       string month = "JUNE";

    Then use expressions like month[0], month[1], etc., or month[i] to access the letters.

    Friday, March 31, 2017 6:22 PM