fen*_*eng 19 c# if-statement async-await
问题描述: 我很惊讶if块中的代码已到达.我认为if块不会被执行.
我完全糊涂了.谁能解释或教我?
private async Task TestMethod()
{
bool ok = false;
City city = City.BJ;
await Task.Delay(100);
ok = true;
if (!ok)//Suppose it won't go into this code block. Because variable 'ok' is true.
{
if (city == City.BJ)//City is enum type.
{
throw new Exception("BJ. Good day.");
}
else
{
throw new Exception("SH. Rainy day");//This row is reached.Weird! But the upper caller method doesn't detect this exception.
}
}
}
enum City
{
BJ = 1,
SH = 2
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
470 次 |
| 最近记录: |