I have an issue with my C# code - somehow I cant get my switch to work, (ex case 1: Charmander(); break;) says "An object reference is required for the non-static field, method, or property "Program.Charmander()" - But I cant seem to figure out why it isnt getting referenced.
class Program
{
string[] PokemonList =
// Entries i vores array af tilfældige Pokémon
{ "Charmander", "Squirtle", "Bulbasaur", "Pikachu", "Eevee", "Gastly", "Jigglypuff" };
int index = 0;
static void Main(string[] args)
{
// array "køn"
string[] gen = { "♂", "♀" };
// Oprettelse af vores array "PokemonList"
string[] PokemonList =
// Entries i vores array af tilfældige Pokémon
{ "Charmander", "Squirtle", "Bulbasaur", "Pikachu", "Eevee", "Gastly", "Jigglypuff" };
foreach (string PokemonSelect in PokemonList)
// Prints the name of all selectable Pokémon
Console.WriteLine(PokemonSelect);
Console.WriteLine("Which Pokémon will you choose?");
//Chooses a random Pokémon from the string PokemonList
Random RandomPokemon = new Random();
int index = RandomPokemon.Next(PokemonList.Length);
Console.WriteLine($"Your opponent is {PokemonList[index]}");
//Menu over choices the user can press
string StringMenu = Console.ReadLine();
int NextChoice = Convert.ToInt32(StringMenu);
switch (NextChoice)
{
case 1:
Charmander();
break;
case 2:
Squirtle();
break;
case 3:
Bulbasaur();
break;
case 4:
Pikachu();
break;
case 5:
Eevee();
break;
case 6:
Gastly();
break;
case 7:
Jigglypuff();
break;
}
Console.WriteLine("Your Pokémon's gender is: " + gen[new Random().Next(0, gen.Length)]);
}
public string Charmander()
{
Console.WriteLine("You choose: Charmander");
return PokemonList[index];
}
public string Squirtle()
{
Console.WriteLine("You choose: {1}");
return PokemonList[index];
}
public string Bulbasaur()
{
Console.WriteLine("You choose: {2}");
return PokemonList[index];
}
public string Pikachu()
{
Console.WriteLine("You choose: {3}");
return PokemonList[index];
}
public string Eevee()
{
Console.WriteLine("You choose: {4}");
return PokemonList[index];
}
public string Gastly()
{
Console.WriteLine("You choose: {5}");
return PokemonList[index];
}
public string Jigglypuff()
{
Console.WriteLine("You choose: {6}");
return PokemonList[index];
}
}
}
...........................................................................