我正在尝试创建一个具有两个类的 C# 程序,这些类将根据用户的输入做出决定以输出响应(例如,用户说岩石,计算机说纸),这使用户总是输。我目前有错误说
“不能在所有情况下(“case1:”、“case2:”、“case3:”)的行上将类型'int'隐式转换为'string'类型。
然而,我已经将“nameClassif”定义为上面的字符串。我也有一个警告:警告 CS0649:字段 'Player.classif' 从未分配给,并且将始终具有其默认值 null
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; set; }
public string Classif { get; set; }
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 ReturnNameOfClassification()
{
string nameClassif;
}
侃侃无极
aluckdog
慕盖茨4494581
相关分类