C# 表单游戏,字符串错误?(vs2015desktop)
问题就在这里C# 表单游戏,字符串错误?(vs2015desktop),c#,winforms,text,C#,Winforms,Text,问题就在这里 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Treasure_Hunter {
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Treasure_Hunter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
我想做的是让它做的是检查aaxe=y/n,如果是yesy,它将以其他方式工作,比如说空
错误
错误CS1525无效的表达式项“=”23
警告CS0642可能错误的空报表寻宝23
错误CS1513}应为寻宝者26
private void Axe_Click(object sender, EventArgs e)
{
string aaxe = "n";
if (aaxe = = 'y');
{
richTextBox1.AppendText("You Used your AXE");
}
else
{
richTextBox1.AppendText("Empty");
}
我正在尝试制作一个寻宝文字游戏。这部分代码总是错误的:
}
private void Pickaxe_Click(object sender, EventArgs e)
{
}
private void Shovel_Click(object sender, EventArgs e)
{
}
private void Candle_Click(object sender, EventArgs e)
{
}
private void Knife_Click(object sender, EventArgs e)
{
}
private void Key_Click(object sender, EventArgs e)
{
}
private void Treasure_Click(object sender, EventArgs e)
{
}
}
}
需要在类级别声明Aaxe
还有,为什么代码中有一个空格“==”,而不是“==”在那之后,我遇到了一个新错误“CS0019运算符”==”不能应用于“string”类型的操作数,而“char”空格很重要。。。另外,听听你的编译器。最后,即使是这样的工作,你也不会进入你的Y区块,只是要考虑的事情。到您编辑的评论。。。继续收听编译器。尝试将“y”更改为y双引号。单引号和双引号也是不同的如果aaxe==y应该是这样的,你需要非常缓慢地开始。请尝试制作一个非常简单的控制台应用程序。然后继续使用类。然后开始使用GUI。按照这种速度,您将把所有的时间都花在堆栈溢出上。这是错误的。请删除if语句上的分号,并且在比较中还有一个编译器错误……你们都是对的。我的缺点是:你不能将字符串与字符进行比较。它将生成一个编译错误。运算符“==”不能应用于“string”和“char”类型的操作数
private void Axe_Click(object sender, EventArgs e)
{
string aaxe = "n";
if (aaxe == ('y').ToString())
{
...