首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么它会给出错误CS1525 ??有什么不好的吗?

为什么它会给出错误CS1525 ??有什么不好的吗?
EN

Stack Overflow用户
提问于 2019-06-13 07:04:10
回答 1查看 4.1K关注 0票数 -4

请帮帮我!!我不知道发生了什么,我的这段愚蠢的代码不能工作。请帮帮我,因为我是c#的新手,我只是想做一些代码来练习。我写了一个"If语句“,通常它应该使用:{},但它没有。还有其他几个问题,下面是代码上面的输出:

代码语言:javascript
复制
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

//代码如下

代码语言:javascript
复制
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);
  }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-13 07:06:25

你遗漏了一个结束语:

代码语言:javascript
复制
if(String.Contains("y")) //<---missing extra )

你有一个额外的括号:

代码语言:javascript
复制
 int question1;
 { //<----what's that doing there?
 Console.WriteLine("LOOOOOL");

重新格式化的代码应该如下所示:

代码语言:javascript
复制
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")可能对您有用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56571389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档