My goal is to make the program print the typing of a Pokemon from user input.
My Pokemon object has members like this
class Pokemon
{
public string Name
{ get; set; }
public string Type
{ get; set; }
public Pokemon(string aName, string aType)
{
Name = aName;
Type = aType;
}
}
In the main program I can create several different Pokemon. So far it's all good, but next I'd like to get a name of a Pokemon as an user input and then the program would access the Pokemon in question. Like this
Pokemon charmander = new Pokemon("Charmander", "fire");
string userInputPokemon = Console.ReadLine();
//if user input was "Charmander" the program should print "Charmander: fire"
Console.WriteLine($"{userInputPokemon.Name}: {userInputPokemon.Type}");
It is obvious to me that there's error in the last line of code. I tried googling about this and came to the conclusion that converting string to a variable name is not possible. If this indeed is impossible, how to get around this? Thank you in advance!