0
How to instantiate this class jogo
?
public class Jogo
{
public string Name { get; set; }
public string Genre { get; }
public string Plataform { get; }
public Jogo(string name, string genre, string plataform)
{
Name = name;
Genre = genre;
Plataform = plataform;
}
}
with the parameters 'Genre' and 'Plataform' of a predefined and immutable list?
I thought about enum
:
enum Genre { Ação, Plataforma, FPS, Aventura, Corrida };
// ou uma lista
var plataform = new List<string>(){ "PS4", "PS5", "Xbox One", "Xbox Series X" };
But I couldn’t instantiate
var game = new Jogo("God of War", <item da List ou Enum>, <item da List ou Enum>);
// eu tentei mudar a propriedade na class 'Jogo'
// com List:
public List<string> Genre { get; }
public List<string> Plataform { get; }
// ou com enum
public Genre category{ get; }
public System Plataform { get; }
How to instantiate?
With one class for 'Platform' and another for 'Genre'... or an Enum within 'Game'? What is the best implementation?
I don’t understand? ...
– novic
I have the Game class, at the time of instantiation I wanted to limit the options of the second parameter 'Enre', not to put anything. That is: new game("string_qualquer", Genre.Ação, Plataform.PS4); So I avoid mistakes of the new game type("string_qualquer", "banana", "pessego");
– Luke Negreiros
So don’t use strings for the type of the field, if what you want is a class or an Enum. C# allows you to define the type of the field. Use as static, non-dynamic typing language.
– Piovezan
tenteus
enum
?.– novic
I’m trying again. Damn it!
– Luke Negreiros
I will put the solution, in case anyone has the same doubt.
– Luke Negreiros