-4

So I have a script to take a word that has been typed and reverse it to tell the person if it is a palindrome or not everything seem to be fine besides a error from this line of code. any idea why as i have been sitting here getting frustrated at it. Let me know if you need more of the code.

ConsoleKeyInfo Keyinfo = Console.readkey(); 

Also have complication of only being able to type one letter instead of writing a word and pressing enter any advice?

plan122
  • 11
  • 5
  • 7
    So what *is* the error? Never, ever post a question saying you've got an error without specifying what the error is. – Jon Skeet Jun 16 '15 at 14:02

1 Answers1

3

C# is case-sensitive.

Console.readkey();

should be

Console.ReadKey();

This method, by definition, reads a key. If you want to read more than one character (the entire line, for example), you should be using Console.ReadLine(), which reads all characters from the input until it reaches a new line.

Since ReadLine and ReadKey return different types, you'll also need to change your variable type (and probably the name as well since it's not keyinfo anymore!)

string line = Console.ReadLine();

Looking at the documentation page of Console.ReadLine, you might notice String is used in some places and string in others. Essentially nothing - string is a C# alias for the .NET framework type named String. More about that in this StackOverflow question: What is the difference between String and string in C#?

Community
  • 1
  • 1
cbr
  • 12,563
  • 3
  • 38
  • 63
  • oh wow i feel stupid haha cheers – plan122 Jun 16 '15 at 14:01
  • 1
    No problem! In the future, you might want to google the method name and find the MSDN (Microsoft Developer Network) page for the method you want. For example, if you want to find all methods (functions) available in the Console class, look at [its MSDN page](https://msdn.microsoft.com/en-us/library/system.console(v=vs.110).aspx). – cbr Jun 16 '15 at 14:03
  • so if i were to change me Console.ReadKey() to ReadLine do i have to change my ConsoleReadKey to ConsoleReadLine? – plan122 Jun 16 '15 at 14:11
  • @plan122 Good question! I can definitely see why it would seem that way. If you open the link I provided in my answer, it will open the documentation page for `Console.ReadLine()`. From there, you can see what type it returns: http://i.imgur.com/8XoQolW.png – cbr Jun 16 '15 at 14:20
  • thanks for looking out the new guy :) – plan122 Jun 16 '15 at 14:22
  • @plan122 We've all been there at some point! If you have any questions related to C# or programming in general which you don't think belong on StackOverflow, you can find my Skype username on [my profile](http://stackoverflow.com/users/996081/cubrr?tab=profile)! – cbr Jun 16 '15 at 14:27