How could I reverse the way a foreach traverses the object? [closed]

0

Next code:

foreach(Control objCtrl in groupBox.Controls)
{
    if (objCtrl is NumericTextBox)
    {
        int i = objCtrl.Text.Length;
        MessageBox.Show(i.ToString());
        if (String.IsNullOrEmpty(objCtrl.Text) || objCtrl.Text == "0,00")
        {
            this.exibeNotificacaoCampoVazio(objCtrl, "Atenção", "O esse campo não pode ser vazio");
            return false;
        }
    }

}
    
asked by anonymous 19.09.2018 / 19:12

1 answer

5

With the extension method IEnumerable<T>.Reverse

Example:

// using System.Collections.Generic;
// using System.Linq;
IEnumerable<int> list = new[] { 1, 2, 3 };

foreach (var item in list.Reverse())
{
    Console.Write(item + " ");
} // saída: 3 2 1
    
19.09.2018 / 19:36