I am creating a basic console application(I am very new to c#) and I am creating a game class to allow for a multi-file project.But It is spitting out an error:
Top-level statements must precede namespace and type declarations.
the class itself is not getting any errors but the code after the class IS.
here is an example to illustrate my point:
public class game
{
Console.WriteLine();
}
int u = 0;
Bare in mind that I do not know how namespaces work in c# and all the examples I could find are in .NET 6.0 or lower
Thank you in advance:D
>Solution :
namespace you_namespace
{
public class game
{
public void output(int u)
{
Console.WriteLine($"u = {u}");
}
}
}
Classes live in namespaces, so I created one to contain the game
class. Variable declarations and initialisations need to be inside a class or a method like output(). Just fooling around here, but it’s the principle you have to grasp. I advice to take a beginners course in C#, to start off prepared.