C# 大括号问题
我正在学习有关制作基于文本的游戏的 C# 教程,但一开始就遇到了问题。以下代码:
namespace GameV2
{
class Level
{
private static Room[,] rooms;
#region Properties
public static Room[,] Rooms
{
get { return rooms; }
}
#endregion
public static void Initialize();
*{*
}
private static *BuildLevel*();
{
}
return false;
}
*}*
给了我 3 个错误。
错误 1 类、结构或接口成员声明中的标记“{”无效
错误 2 需要类、委托、枚举、接口或结构
错误 3 类型或命名空间定义,或预期文件结尾
斜体表示按顺序排列的错误。由于某些原因,Visual C# Express 不允许我在方法定义中使用 { ,并将最终的 } 推出代码框。关于为什么会发生这种情况有什么想法吗?
I'm following a tutorial on C# on making a text-based game and I ran into an issue right at the start. The following code:
namespace GameV2
{
class Level
{
private static Room[,] rooms;
#region Properties
public static Room[,] Rooms
{
get { return rooms; }
}
#endregion
public static void Initialize();
*{*
}
private static *BuildLevel*();
{
}
return false;
}
*}*
gives me 3 errors.
Error 1 Invalid token '{' in class, struct, or interface member declaration
Error 2 Expected class, delegate, enum, interface, or struct
Error 3 Type or namespace definition, or end-of-file expected
The italics represent the errors in order. Fr some reason Visual c# express won't let me use { in a method definition, and pushes my final } out of the code box. Any ideas on why this happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
方法后面没有分号。您可能会将它们与 C 混淆
方法原型。
BuildLevel 应该有一个返回类型。
所有语句都必须位于方法内部,只能在方法外部进行声明
这应该编译:
You don't have semicolons after methods. You may be confusing them for C
method prototypes.
BuildLevel should have a return type.
All statements have to be inside methods, you can only have declarations outside of methods
This should compile:
这些是声明。它们后面不能跟
{ }
。删除;
就可以了。这缺少返回类型。
Those are declarations. They cannot be followed by
{ }
. Remove the;
and it will work.This is missing a return type.
去掉两个
;
Remove the two
;
应该是
should be
从函数声明末尾(左大括号之前)删除分号。
Remove the semicolons from the end of your function declarations (before the opening curly brace).
注意分号。方法名称与其主体之间有分号。
Watch out for the semicolons. You have semicolons between the method names and their bodies.
这可能是问题所在:
您没有指定返回类型,并且
return false;
应该位于括号内。This may be the problem:
You didn't specify a return type, and the
return false;
should be inside the brackets.