Как вырваться из заявления IF

У меня все еще была проблема с передачей формата yyyy-MM-dd, но я обошел его, изменив Date.cshtml:

@model DateTime?

@{
    string date = string.Empty;
    if (Model != null)
    {
        date = string.Format("{0}-{1}-{2}", Model.Value.Year, Model.Value.Month, Model.Value.Day);
    }

    @Html.TextBox(string.Empty, date, new { @class = "datefield", type = "date"  })
}
24
задан szpic 27 March 2015 в 09:35
поделиться

1 ответ

Другой способ начать с c# 7.0 использовал бы локальные функции. Вы могли назвать локальную функцию с понятным именем и назвать ее непосредственно прежде, чем объявить это (для ясности). Вот Ваш переписанный пример:

public void Method()
{
    // Some code here
    bool something = true, something2 = true;

    DoSomething();
    void DoSomething()
    {
        if (something)
        {
            //some code
            if (something2)
            {
                // now I should break from ifs and go to te code outside ifs
                return;
            }
            return;
        }
    }

    // The code i want to go if the second if is true
    // More code here
}
0
ответ дан 28 November 2019 в 06:49
поделиться