我正在尝试编写一个while循环验证来验证用户在输入具有以下条件的句子时的响应:
字符串为空或空
句子必须至少六个字。
我能够让 null 或 empty 条件按预期工作,但“必须至少是六个字”目前没有按预期工作。每当我输入一个少于六个单词的句子时,它都会接受它。但是,如果我输入一个包含六个或更多单词的句子,它会在不应该时提示已建立的错误消息。
while (String.IsNullOrEmpty(sentence) || sentence.Length != 6)
{
if (String.IsNullOrEmpty(sentence))
{
Console.WriteLine("Please, do not leave the sentence field empty!");
Console.WriteLine("Enter your desired sentence again: ");
sentence = ReadLine();
}
else
{
Console.WriteLine("\r\nThe sentece entered isn't valid. Must have a least six words!");
Console.WriteLine("Enter a sentence with a least 6 words: ");
sentence = ReadLine();
}
}
我到底做错了什么?
慕姐8265434
DIEA
倚天杖
慕运维8079593
随时随地看视频慕课网APP
相关分类