C# n'是错误的,我试着运行它时纠正了它。但我在尝试运行此解决方案时仍然出现错误。我认为错误是因为我复制了我的announce和getstring方法,但没有意识到这一点。在把这些方法放回去后我重新测试了一遍,结果很有效。但是它有一个缺陷,如果“default
C# n'是错误的,我试着运行它时纠正了它。但我在尝试运行此解决方案时仍然出现错误。我认为错误是因为我复制了我的announce和getstring方法,但没有意识到这一点。在把这些方法放回去后我重新测试了一遍,结果很有效。但是它有一个缺陷,如果“default,c#,methods,C#,Methods,n'是错误的,我试着运行它时纠正了它。但我在尝试运行此解决方案时仍然出现错误。我认为错误是因为我复制了我的announce和getstring方法,但没有意识到这一点。在把这些方法放回去后我重新测试了一遍,结果很有效。但是它有一个缺陷,如果“default”语句打印到控制台,任何结果都会得到一个“我不知道”命令来反复打印。所以如果我输入V那么E@GrantWinney:谢谢亲爱的:)编辑了我的帖子。我尝试了这个,但是我犯了很多错误。我看到单词is关键字“return”是错误的,我在尝试运行它时更
n'是错误的,我试着运行它时纠正了它。但我在尝试运行此解决方案时仍然出现错误。我认为错误是因为我复制了我的announce和getstring方法,但没有意识到这一点。在把这些方法放回去后我重新测试了一遍,结果很有效。但是它有一个缺陷,如果“default”语句打印到控制台,任何结果都会得到一个“我不知道”命令来反复打印。所以如果我输入V那么E@GrantWinney:谢谢亲爱的:)编辑了我的帖子。我尝试了这个,但是我犯了很多错误。我看到单词is关键字“return”是错误的,我在尝试运行它时更正了它。但我在尝试运行此解决方案时仍然出现错误。我认为错误是因为我复制了我的announce和getstring方法,但没有意识到这一点。在把这些方法放回去后我重新测试了一遍,结果很有效。但是它有一个缺陷,如果“default”语句打印到控制台,任何结果都会得到一个“我不知道”命令来反复打印。所以如果我进入V,那么EWOW。我认为这是非常优雅和聪明的(我的新手无论如何都能完全理解它)。我修改了我的代码,用select方法()注释掉了elseif(command=='e'),然后运行它,它成功了。我在这里学到了很多。谢谢你,格兰特。我认为这是非常优雅和聪明的(我的新手无论如何都能完全理解它)。我修改了我的代码,用select方法()注释掉了elseif(command=='e'),然后运行它,它成功了。我在这里学到了很多。谢谢你,格兰特。我觉得这真的太棒了,还有很多建议让我的大脑以一种非常棒的方式融化——谢谢大家。我不知道bool可以用来向控制台发送文本。我必须深入研究这件事。没问题,很高兴我能帮上忙。bool向控制台发送文本是什么意思?bool只是一个标志,指示是否使用了正确的命令。我们有一个bool,该方法将文本发送到字符串,我非常期待bool返回true或false,我想我可以在该方法中使用其他东西,并将其发送到控制台。我认为这也非常棒,正如许多建议一样,这些建议让我的大脑以令人敬畏的方式融化——谢谢大家。我不知道bool可以用来向控制台发送文本。我必须深入研究这件事。没问题,很高兴我能帮上忙。bool向控制台发送文本是什么意思?bool只是一个标志,指示是否使用了正确的命令。我们有一个bool,该方法将文本发送到字符串,我非常担心bool返回true或false,我完全没有想到我可以在该方法中使用其他东西,并将其发送到控制台。
class Program
{
public void Play(){
Announcer(" \n\nProgram Name Goes Here \n\n");
while (true)
{
/*
* Allow user to display director of books (Three)
* allow user to select specific book with any comments it might have (2-4 comments)
* Allow user to enter a specific comment
* display book with new new added comment
* Allow user to exit book
* */
Select();
Console.Read();
}
}
public void Announcer(String strTxt){Console.Write(strTxt);}
public String GetString(String strData){
Console.WriteLine(strData);
return Console.ReadLine();//traffic control => back to program
}
public void Select(){
String command = GetString(" \n\n(V)eiw, (S)elect, (C)omment, (R)emove, (E)xit").ToLower();
if (command == "v")
{ Announcer(" \n\nEnter listing: ");
//ViewDirectory();//call view directory here
}
else if (command == "c")
{ Announcer(" \n\nEnter comment: "); }
else if (command == "s")
{
//we want to do a selectString method that returns length of selects here
String select = GetString(" \n\n(1)st Selection, (2)nd Selection, (3)rd book, (E)xit").ToLower();
if (select == "1")
{ Announcer(" \n\nDisplay book info + allow for user comment entering"); }
else if (select == "2")
{ Announcer(" \n\nDisplay book info + allow for user comment entering"); }
else if (select == "3")
{ Announcer(" \n\nDisplay book info + allow for user comment entering"); }
}
else if (command == "e") { break; }
else { Console.WriteLine("\n\nOopsy, I don't know that command! \n\n"); }
}
}
//public void ViewDirectory(){
// Console.WriteLine("stuff");
//}
class Program
{
public void Play(){
Announcer(" \n\nProgram Name Goes Here \n\n");
while (true)
{
/*
* Allow user to display director of books (Three)
* allow user to select specific book with any comments it might have (2-4 comments)
* Allow user to enter a specific comment
* display book with new new added comment
* Allow user to exit book
* */
if(Select())
break; //break if you get return value of Select() as true
Console.Read();
}
}
public bool Select(){
String command = GetString(" \n\n(V)eiw, (S)elect, (C)omment, (R)emove, (E)xit").ToLower();
if (command == "v")
{ Announcer(" \n\nEnter listing: ");
//ViewDirectory();//call view directory here
return false;
}
else if (command == "c")
{ Announcer(" \n\nEnter comment: "); return false;}
else if (command == "s")
{
//we want to do a selectString method that returns length of selects here
String select = GetString(" \n\n(1)st Selection, (2)nd Selection, (3)rd book, (E)xit").ToLower();
if (select == "1")
{ Announcer(" \n\nDisplay book info + allow for user comment entering"); }
else if (select == "2")
{ Announcer(" \n\nDisplay book info + allow for user comment entering"); }
else if (select == "3")
{ Announcer(" \n\nDisplay book info + allow for user comment entering"); }
return false;
}
else if (command == "e") { return true; }
else { Console.WriteLine("\n\nOopsy, I don't know that command! \n\n"); return
false; }
}
}
while (true)
{
var command
= GetString(" \n\n(V)eiw, (S)elect, (C)omment, (R)emove, (E)xit").ToLower();
if (command == "e")
break;
Select(command);
Console.Read();
}
if(Select())
{
break;
}
while (Select())
{
/*
* Allow user to display director of books (Three)
* allow user to select specific book with any comments it might have (2-4 comments)
* Allow user to enter a specific comment
* display book with new new added comment
* Allow user to exit book
* */
Console.Read();
}
public bool Select()
{
bool isValid = true;
String command = GetString(" \n\n(V)eiw, (S)elect, (C)omment, (R)emove, (E)xit").ToLower();
switch (command)
{
case "v":
Announcer(" \n\nEnter listing: ");
//ViewDirectory();//call view directory here
break;
case "c":
Announcer(" \n\nEnter comment: ");
break;
case "s":
{
//we want to do a selectString method that returns length of selects here
String select = GetString(" \n\n(1)st Selection, (2)nd Selection, (3)rd book, (E)xit").ToLower()
switch (select)
{
case "1":
Announcer(" \n\nDisplay book info + allow for user comment entering");
break;
case "2":
Announcer(" \n\nDisplay book info + allow for user comment entering");
break;
case "3":
Announcer(" \n\nDisplay book info + allow for user comment entering");
break;
}
break;
}
case "e":
isValid = false;
break;
default:
Console.WriteLine("\n\nOopsy, I don't know that command! \n\n");
break;
}
return isValid;
}
switch (val)
{
//this line should not be here
dosomething1(); //==>error
case "low":
dosomething2();
break;
case "high":
dosomething3();
break;
}