请帮帮我!!我不知道发生了什么,我的这段愚蠢的代码不能工作。请帮帮我,因为我是c#的新手,我只是想做一些代码来练习。我写了一个"If语句“,通常它应该使用:{},但它没有。还有其他几个问题,下面是代码上面的输出:
main.cs(14,30): error CS1525: Unexpected symbol `{'
main.cs(17,6): error CS1525: Unexpected symbol `else'
main.cs(23,246): error CS1525: Unexpected symbol `end-of-file'
Compilation failed: 3 error(s), 0 warnings
compiler exit status 1
//代码如下
using System;
public class LOOOOOL {
public static void Main(String [] args)
{
int enterInfo;
int question1;
{
Console.WriteLine("LOOOOOL");
enterInfo = Console.ReadLine();
Console.WriteLine(enterInfo);
question1 = Console.WriteLine("Is that what you wrote ???");
if(String.Contains("y") {
Console.WriteLine("So that's cool, right ???");
}
else
{
Console.WriteLine("Can you re-write it please ???");
question1 = Console.ReadLine();
Console.WriteLine(question1);
}
}
发布于 2019-06-13 07:06:25
你遗漏了一个结束语:
if(String.Contains("y")) //<---missing extra )
你有一个额外的括号:
int question1;
{ //<----what's that doing there?
Console.WriteLine("LOOOOOL");
重新格式化的代码应该如下所示:
using System;
public class LOOOOOL
{
public static void Main(String [] args)
{
int enterInfo;
int question1;
Console.WriteLine("LOOOOOL");
enterInfo = Console.ReadLine();
Console.WriteLine(enterInfo);
question1 = Console.WriteLine("Is that what you wrote ???");
if(String.Contains("y"))
{
Console.WriteLine("So that's cool, right ???");
}
else
{
Console.WriteLine("Can you re-write it please ???");
question1 = Console.ReadLine();
Console.WriteLine(question1);
}
}
}
此外,您的变量是int
...它将永远不会包含“”....可能需要将这两个字符串更改为字符串
还有..。String.Contains()
...您要检查的是什么字符串?您需要查看的内容:)
也许,enterInfo.Contains("y")
可能对您有用。
https://stackoverflow.com/questions/56571389
复制相似问题