samedi 6 avril 2019

How do I perform a check with over 1000 if statements?

I have a list of newspapers and magazines. It counts to 1374 to be exact and all my files are named like abcd_20190406.xml, where abcd is the filename abbreviaton and 20190406 is the date in yyyyMMdd format.

So what I want is that, if I press the button in my WindowsForm, it will search for the abcd in the list. If found, it will fill it's respective data which will be mentioned in my form's TextBoxes.

if (Path.GetFileNameWithoutExtension(cboSource.Text).StartsWith("aamfr"))
{
        TextBoxPublication.Text = "Anti-âge Magazine";
        TextBoxAbbreviation.Text = "aamfr";
        TextBoxLanguage.Text="fr";
}

if (Path.GetFileNameWithoutExtension(cboSource.Text).StartsWith("wic"))
{
        TextBoxPublication.Text = "Wisden Cricket Monthly";
        TextBoxAbbreviation.Text = "wic";
        TextBoxLanguage.Text="en";
}

And so on. This is my current approach. Giving 1374 if conditions. So is there a faster way or a more better way of doing this?

I thought of creating a List<string> and doing it but I have no clue how to proceed. I don't even know if that is the correct way of doing this.

Please help.

Aucun commentaire:

Enregistrer un commentaire