有了这段代码,我不明白为什么如果在 finally 块中分配一个变量不理解它总是会被分配。我想我错过了一个不会分配货币的有效选项。如果您知道,将很高兴了解原因。非常感谢!
谢谢!
CurrencyVO currency;
try
{
if (idConnection.HasValue && idConnection != 0)
{
currencyConnection = client.GetConnection(idConnection.Value);
model.Connection = currencyConnection;
}
else
{
int providerUserKey = (int)Models.UserModel.GetUser().ProviderUserKey;
currencyConnection = client.GetConnection(providerUserKey);
}
currency = model.Currencies.SingleOrDefault(c => c.IdCountry == currencyConnection.idcountry) ?? new CurrencyVO();
}
catch
{
currency = new CurrencyVO();
}
finally
{
model.PublishedContainer.Currency = currency;
}
错误发生在 finally 块上。如果我像这样将它从 finally 块中取出:
} catch {
currency = new CurrencyVO();
}
model.PublishedContainer.Currency = currency;
它工作正常。