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?
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: