I have this code, which I think is not very efficient since it checks for the current Language for every item in the list:
foreach (InfoSpecies c in list.Especies) //list has 37 items
{
if (Localization.Instance.CurrentLanguage == SystemLanguage.Portuguese)
{
nomeComum = c.NomeComum;
}
else
{
nomeComum = c.CommonName;
}
//do something with nomeComum
}
I’m trying to change the code in order to perform the test only once, just before running the foreach cycle. I think it has to be something like this:
if (Localization.Instance.CurrentLanguage == SystemLanguage.Portuguese)
{
nomeComum = c.NomeComum;
}
else
{
nomeComum = c.CommonName;
}
foreach (InfoSpecies c in list.Especies)
{
//do something with nomeComum
}
But this is obviously not working, since c.NomeComum will only exist during the foreach cycle.
Is there a way to pass the apropriate assignment after the if cycle has run, in order for the right item to be selected from the list?
Can someone help me?
Thanks