CS0201错误代码,新程序员请帮忙 [英] CS0201 error code, new programmer please help

查看:74
本文介绍了CS0201错误代码,新程序员请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用c#编写一个2人摇滚剪刀游戏的代码,并尽可能保持基本。我以为我终于搞清楚了然后得到了这个错误。有人可以帮我推动我朝正确的方向发展吗?



I am trying to write code for a 2 player rock paper scissors game in c# and keeping it as basic as possible. I thought i had finally figured it out and then got this error. Can someone please help push me in the right direction?

/**
Programmer: Corey Flower
Date Written: April 10, 2016
This program allows the user to play rock paper scissors.
*/
using System;

namespace m3
{
    class Program
    {
        static void Main(string[] args)
            {
                Console.WriteLine("Player 1, do you choose rock,paper or scissors");
                string Player1Choice = Console.ReadLine();
                
                Console.WriteLine("Player 2, do you choose rock,paper or scissors");
                string Player2Choice = Console.ReadLine();
                

                if (Player1Choice == "rock")
                {
                    if (Player2Choice == "rock")
                    {
                        Console.WriteLine("Both players chose rock");
                        Console.WriteLine("It is a tie ");
                    }
                    else if (Player2Choice == "paper")
                    {
                        Console.WriteLine("Player 1 chose rock, Player 2 chose paper");
                        Console.WriteLine("Player 2 wins!");

                    }
                    else if (Player2Choice == "scissors")
                    {
                        Console.WriteLine("Player 1 chose rock, Player 2 chose scissors");
                        Console.WriteLine("Player 1 wins! ");
                    }
                    else
                    {
                        Console.WriteLine("You must choose rock,paper or scissors!");

                    }

                }

                else if (Player1Choice == "paper")
                {
                    if (Player2Choice == "rock")
                    {
                        Console.WriteLine("Player 1 chose paper, Player 2 chose rock");
                        Console.WriteLine("Player 1 wins!");

                    }
                    else if (Player2Choice == "paper")
                    {
                        Console.WriteLine("Both players chose paper");
                        Console.WriteLine("It is a tie! ");

                    }
                    else if (Player2Choice == "scissors")
                    {
                        Console.WriteLine("Player 1 chose paper, Player 2 chose scissors");
                        Console.WriteLine("Player 2 wins!");
                    }
                    else
                    {
                        Console.WriteLine("You must choose rock,paper or scissors!");
                    }
                }
                else if (Player1Choice == "scissors")
                {
                    if (Player2Choice == "rock")
                    {
                        Console.WriteLine("Player 1 chose scissors, Player 2 chose rock");
                        Console.WriteLine("Player 2 wins!");

                    }
                    else if (Player2Choice == "paper")
                    {
                        Console.WriteLine("Player 1 chose scissors, Player 2 chose paper");
                        Console.WriteLine("Player 1 wins!");

                    }
                    else if (Player2Choice == "scissors")
                    {
                        Console.WriteLine("Both players chose scissors");
                        Console.WriteLine("It is a tie!");

                    }
                    else
                    {
                        Console.WriteLine("You must choose rock,paper or scissors!");

                    }

                }
                    (Console.ReadLine() == "yes");
        }
    }
}





我尝试了什么:



我已经google了,在其他论坛上发帖,遍历了我的教科书,并运行了调试器,到目前为止都无济于事。



What I have tried:

I have googled, posted on other forums, traversed my text book, and ran debuggers, all to no avail so far.

推荐答案

想通了,最后一行代码导致错误并且是不必要的
figured it out, the last line of code was causing an error and was unecessary


当你发布关于你的错误时,发布一个非常好的主意错误附带的完整消息以及它出现在哪一行。



如果您使用的是Visual Studio,则可以双击错误中的错误列表窗口和IDE将带您到错误的行。



在这种情况下它是
When you post about your errors it is a very good idea to post the full message that comes with the error and on which line that it occurred.

If you are using Visual Studio then you can double-click on the error in the "Error List" window and the IDE will take you to the line in error.

In this case it is
(Console.ReadLine() == "yes");



并且错误是


and the error is

Quote:

错误11只有赋值,调用,递增,递减,等待和新o bject表达式可用作语句

Error 11 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement



目前还不完全清楚你想用该行做什么。也许你打算将它作为 if 语句的一部分 - 在这种情况下你将需要if以及如果输入确实是是该怎么做的声明。或者你是否只是打算让用户点击一个关键的contine? (其中Console.ReadKey();可能是更好的选择


It's not entirely clear what you wanted to do with that line. Perhaps you meant to have it as part of an if statement - in which case you will need the "if" and a statement of what to do if the input is indeed "yes". Or did you just intend for the User to hit a key to contine? (In which Console.ReadKey(); is probably a better option


这篇关于CS0201错误代码,新程序员请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆