gpt4 book ai didi

c# - C# "finally" block 是否总是执行?

转载 作者:IT王子 更新时间:2023-10-29 03:43:18 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Will code in a Finally statement fire if I return a value in a Try block?

考虑以下代码 C# 代码。 “finally” block 是否执行?

public void DoesThisExecute() {
string ext = "xlsx";
string message = string.Empty;
try {
switch (ext) {
case "xls": message = "Great choice!"; break;
case "csv": message = "Better choice!"; break;
case "exe": message = "Do not try to break me!"; break;
default:
message = "You will not win!";
return;
}
}
catch (Exception) {
// Handle an exception.
}
finally {
MessageBox.Show(message);
}
}

哈,在我写完这篇文章后,我意识到我可以在 Visual Studio 中自己测试它。但是,请随时回答!

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com