Hello everybody, i'm new in C# and i have a problem:
how to make a loop(what will be in paranthesises?) that asks user to enter a word (then my method checks whether it is a palindrome or not) until user presses Ctrl+Z.

PLZ help, i'll glad to any advise.

Is using the standard CTRL+C an option? You could flag while you were in the middle of a loop and break out of the loop instead of killing the console application. I think you have to implement a considerable amount of code to start handling intercepts for CTRL+<key> in console applications because they don't pump messages like a standard windows form application.

The problem is that, as far as I can tell, you cannot readily intercept a keystroke. Take a look at this article:
http://www.codeproject.com/KB/dotnet/ConsolePasswordInput.aspx

If you start using .ReadKey() so you can capture the modifiers on the key press then you will have to create your own string taking in to account caps lock, shift, etc. for character casing.

This seems like a simple enough question but very difficult in implementing.

Is using the standard CTRL+C an option? You could flag while you were in the middle of a loop and break out of the loop instead of killing the console application. I think you have to implement a considerable amount of code to start handling intercepts for CTRL+<key> in console applications because they don't pump messages like a standard windows form application.

The problem is that, as far as I can tell, you cannot readily intercept a keystroke. Take a look at this article:
http://www.codeproject.com/KB/dotnet/ConsolePasswordInput.aspx

If you start using .ReadKey() so you can capture the modifiers on the key press then you will have to create your own string taking in to account caps lock, shift, etc. for character casing.

This seems like a simple enough question but very difficult in implementing.

O, I think you did not understand what i mean)) I've already found the solution and here it is:

string s = Console.ReadLine();
while(s!=null)
{
      .....
      .....
      s = Console.ReadLine();
}

So, this is what i wanted to know)) Anyway, thank you very much)

I think I did misunderstand your question, but i'm glad you found a solution.

Please mark this thread as solved if you have found an answer to your question and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.