lundi 4 février 2019

Is there a better way to do nothing in a if, else if, else sequence

I'm doing an if, else if, else sequence within a foreach loop. In one of the states I don't want do do anything. Looks kind of weird and i'm wondering if there is a better way to do this?

foreach (var item in collection)
{
    if (item.Contains("some text"))
    {
        removeNext = true;
        myList.Add(item);
    }
    else if (item.ToUpper().Contains("TEXT IN UPPER") | item.Contains("some other text"))
    {
        // do nada
    }
    else if (removeNext)
        removeNext = false;
    else
        myList.Add(item);
}

Aucun commentaire:

Enregistrer un commentaire