Код: Выделить всё
public static void TryDoSomething(int value, out bool itWorked)
{
itWorked = true;
if (someFavourableCondition)
{
// if I didn't assign itWorked variable before this point,
// I get an error: "Parameter itWorked must be assigned upon exit."
return;
}
// try to do thing
itWorked = // success of attempt to do thing
}
Код: Выделить всё
public static void TryDoSomething(int value, out bool itWorked = true)
{
if (someFavourableCondition)
{
// itWorked was already assigned with a default value
// so no compile errors.
return;
}
// try to do thing
itWorked = // success of attempt to do thing
}
Подробнее здесь: https://stackoverflow.com/questions/239 ... ault-value
Мобильная версия