Answer the question
In order to leave comments, you need to log in
Split project into multiple files?
Hello.
I use SFML.NET and, accordingly, C#. The question arose - is it possible to move certain methods and variables into separate files? For example, I have the gameInit() and gameDraw() methods, as well as the username variable , which is set in Program.cs when the program starts. Can I put these methods in separate files and make the variable global?
As a result, I should be able to call methods in Program.cs with a simple gameInit 'om, and have read and write access to the username variable from any element of the project - be it the main project file or a file with mathematical functions.
Google gives only a certain partial class , which, in the process, cannot be scattered over several files, as well as a categorical answer that there is no creation of global variables and methods in C #.
I ask for help here, for the last stronghold.
Answer the question
In order to leave comments, you need to log in
is it possible to move some methods and variables into separate files? For example, I have gameInit() and gameDraw(), <...> methods. Can I put these methods in separate files<...>?
static partial class Program
{
static void Main()
{
GameInit();
GameDraw();
}
}
static partial class Program
{
static void GameInit()
{
// Game init here
}
static void GameDraw()
{
// Game draw here
}
}
and make the variable global
static partial class Program
{
public static String Username;
}
var username = Program.Username;
There are no global variables and methods in c#. You can make a static (or normal) class and place a static field (property) and static methods in it. Get about what you need.
The partial only allows you to place the description of the class in several files for convenience.
In general, in c # all classes, nothing can be created outside the class (structure). Those. there are no global variables and methods. But a static method and a static field (property) are about what you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question