continue on @Olivier answers
Stats class should be moved to it's File and should contain all necessary methods
public class Stats
{
public int HP { get; set; }
public int Attack { get; set; }
public int Defense { get; set; }
public int SpAttack { get; set; }
public int SpDefense { get; set; }
public int Speed { get; set; }
public List<string> GetStateAsStrings()
{
return [
$"{nameof(HP)} = {HP}",
$"{nameof(Attack)} = {Attack}",
$"{nameof(Defense)} = {Defense}",
$"{nameof(SpAttack)} = {SpAttack}",
$"{nameof(Speed)} = {Speed}",
];
}
public override string ToString()
{
return String.Join(Environment.NewLine, GetStateAsStrings());
}
}
now you can use it as following
public class Pokemon
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public List<string> Types { get; set; } = []; // Plural Names (i.e collections) should be Plural Name ('Types' insted of `type`)
public Stats Stats { get; set; } = new();
// ....
public List<string> GetStatsList()
{
return Stats.GetStateAsStrings();
}
}
actually, you can Eliminate this method GetStatsList and use Stats directly as following
private void ResultsWindow_DoubleClick(object sender, EventArgs e)
{
Pokemon SelectedPokemon = p.GetSelectedPokemonData(ResultsWindow.SelectedItem.ToString(), pokemonData); // variable names should be representative instead of 'result' better to use 'selectedPokemon' make more sense
flowLayoutPanel1.Visible = true;
TypeBox.Text = String.Join(Environment.NewLine, SelectedPokemon.Types);
PokemonStats.Text = SelectedPokemon.Stats.ToString(); // Stats know how to render itself as string due to we override the ToString() method
}
Naming
Pay attention on how you Name properties, variables and Methods Name
- Properties and Variables should be descriptive noun and don't use generic or anonymous names, for example in your code
BindingList<string> listfor the reader it should search on your code what do you do with this magic list it would be better to name itFilteredPokemonNames - Methods should be Verbs and you do good job in this point by choosing this names
LoadPokemonDataGetPokemonNamesFilterResults
readonly modifier
fields and properties that you initialize and never need to reassign, it's better to mark it as readonly
public partial class Pokedex : Form
{
readonly BindingList<string> filteredPokemonNames = [];
readonly List<string> pokemonNames = [];
readonly List<Pokemon> pokemonData = [];
// ...
}