GhostCavalry
New member
- Joined
- Jan 11, 2017
- Messages
- 1
- Programming Experience
- Beginner
Hello!
I need your help with Do & While.
When I debug the code and input a whitespace for the first time it shows "Input is invalid".
But when I input a legit string for the second time it shows me "Input is Invalid" and proceeds to the Readkey method.
How can I fix this?
Here is the code:
Thanks in advance!
I need your help with Do & While.
When I debug the code and input a whitespace for the first time it shows "Input is invalid".
But when I input a legit string for the second time it shows me "Input is Invalid" and proceeds to the Readkey method.
How can I fix this?
Here is the code:
C#:
[COLOR=#0000ff]public static void[/COLOR] Main(string[] args)
{
Test();
Console.ReadKey();
}
[COLOR=#0000ff]static void[/COLOR] Test()
{
[COLOR=#0000cd]string [/COLOR]SString;
SString = [COLOR=#0000cd]Console[/COLOR].ReadLine();
if ([COLOR=#0000cd]string[/COLOR].IsNullOrWhiteSpace(SString))
{
[COLOR=#0000cd]Console[/COLOR].WriteLine("Input is Invalid");
[COLOR=#0000cd]do[/COLOR]
{
SString = [COLOR=#0000cd]Console[/COLOR].ReadLine();
[COLOR=#0000cd]Console[/COLOR].WriteLine("Input is Invalid");
} [COLOR=#0000cd]while [/COLOR]([COLOR=#0000ff]string[/COLOR].IsNullOrWhiteSpace(SString));
}
[COLOR=#0000cd]else [/COLOR]
{
[COLOR=#0000cd]Console[/COLOR].WriteLine("Ok!");
}
Thanks in advance!