c# - 我收到此代码的 StackOverflowException 错误。我一直无法找出错误
问题描述
我正在尝试用 C# 中的两个类制作一个剪刀石头布的决策者。我认为很多这可能是错误的,所以去城里。
using System;
using static System.Console;
namespace Tes
{
class PlayerApp
{
public static void Main()
{
Player player1 = new Player();
player1.PlayerChoice = InputValue();
player1.Classif = InputValue();
Clear();
Write(player1);
Write("\n\n\n\n");
ReadKey();
}
public static string InputValue()
{
Write("Please enter rock, paper, or scissors:\t");
return ReadLine();
}
}
class Player
{
private string classif;
// constructors
public Player()
{}
public Player(string pC)
{
PlayerChoice = pC;
}
// properties
public string PlayerChoice
{
get
{
return PlayerChoice;
}
set
{
PlayerChoice = value;
}
}
public string Classif
{
get
{
return classif;
}
set
{
classif = value;
}
}
public double SetFine()
{
if (classif == "rock")
{
WriteLine("The computer chose paper. You lose.");
}
else if (classif == "paper")
{
WriteLine("The computer chose scissors. You lose.");
}
else if (classif == "scissors")
{
WriteLine("The computer chose rock. You lose.");
}
return SetFine();
}
}
}
解决方案
代替
public string PlayerChoice
{
get
{
return PlayerChoice;
}
set
{
PlayerChoice = value;
}
}
public string Classif
{
get
{
return classif;
}
set
{
classif = value;
}
}
和
public string PlayerChoice { get; set; }
public string Classif { get; set; }
推荐阅读
- kotlin - 为什么我会收到 TornadoFX DataGrid 类型错误?
- lua - lua 5.3 lpeg:Cmt、Cb 和 / 运算符
- java - 没有 complexType 的 Apache cxf soap wsdl
- python - 在 Mask RCNN 中计算 mAP,实例分割
- c - 如何在C中比较两个没有秒的日期
- windows - Windows 命令列出过期帐户并排除设置为从不的帐户
- javascript - 无法在剧作家中捕获 response.json()
- python - 手动将 StreamHandler 添加到记录器会中断 IPython 提示
- laravel - 如何在 Laravel 中防止重复发票编号
- blockchain - 如何通过自己的区块链将加密货币从钱包转移到另一个钱包?