I am learning to use C# and I want to make a trivia game, I would like to have different files such as a file with the player's data, another file with the questions and another file where I save the answers, and then execute all together, but I do not know how to do it.
At the moment I only have 2 files, in which I only print characters by console using
Console.WriteLine("Hello World in Question file!");
but I would like different files to be executed in a cascade-like order.
This is the Question.cs file
The problem is not that you have many files but that in a console application you can only have one entry point, that is, a method
static void Main
. In that case you have two so it doesn't compile.To achieve what you want, you could create multiple classes, one in each file (although not necessary but great practice) and use them inside the Main method.
Example:
So, inside your Main method you can make use of them:
If you need to use the properties of one object in another there are several ways to do it. One of them is to store a reference to an object as an attribute. For example, if we wanted to use the player's name within Questions:
And inside Program.cs:
I recommend you study the concepts of classes, objects, encapsulation so that you can understand it better and reach better solutions.