C # - Эффективность проверки ненулевой длины с несколькими текстовыми полями

У меня есть шесть текстовых полей, и пока в одном из них есть допустимый ввод, я хочу, чтобы моя программа продолжала импортировать код. Проблема в том, что я не знаю, как это сделать наиболее эффективно. Две альтернативы, которые я придумал, таковы:

Версия 1:

        //if no paths are specified the user is shown an error and the program
        //will do nothing
        if ((txtForecastFTE.Text.Length != 0)
            || (txtActualFTE.Text.Length != 0)
            || (txtForecastAHT.Text.Length != 0)
            || (txtActualAHT.Text.Length != 0)
            || (txtForecastVolume.Text.Length != 0)
            || (txtActualVolume.Text.Length != 0))
        {
            if (txtForecastFTE.Text.Length != 0)
            {
                //import code
            }//end if

            if (txtActualFTE.Text.Length != 0)
            {
                //import code
            }//end if

            if (txtForecastAHT.Text.Length != 0)
            {
                //import code
            }//end if

            if (txtActualAHT.Text.Length != 0)
            {
                //import code
            }//end if

            if (txtForecastVolume.Text.Length != 0)
            {
                //import code
            }//end if

            if (txtActualVolume.Text.Length != 0)
            {
                //import code
            }//end if
        }//end if
        else
        {
            MessageBox.Show("You must enter the path for at least one file.");
        }//end if-else
    }//end import code

Версия 2:

        //if no paths are specified the user is shown an error and the program
        //will do nothing
        if (txtForecastFTE.Text.Length != 0)
        {
    pathTrue = true;
            //import code
        }//end if

        if (txtActualFTE.Text.Length != 0)
        {
    pathTrue = true;
            //import code
        }//end if

        if (txtForecastAHT.Text.Length != 0)
        {
    pathTrue = true;
            //import code
        }//end if

        if (txtActualAHT.Text.Length != 0)
        {
    pathTrue = true;
            //import code
        }//end if

        if (txtForecastVolume.Text.Length != 0)
        {
    pathTrue = true;
            //import code
        }//end if

        if (txtActualVolume.Text.Length != 0)
        {
    pathTrue = true;
            //import code
        }//end if

        if (!pathTrue)
        {
            MessageBox.Show("You must enter the path for at least one file.");
        }//end if
    }//end import code

Очевидно, я добавлю дополнительную проверку (try-catch) в каждый раздел импорта файлов, но это это основная суть.

Любая помощь приветствуется :) Если есть другие варианты, которые были бы более эффективными, чем любая из двух представленных версий, пожалуйста, не Не стесняйтесь выдвигать это. Спасибо, ребята.

1
задан mispecialist 9 September 2010 в 02:12
поделиться