- switch
在case中可以使用goto default; 或是goto case “…”;
以避免重覆的程式碼。
switch (input)
{
case "111":
Console.WriteLine("...");
goto case "password"; //goto case "..." , 要記得要有case
case "password":
Console.WriteLine("o");
break;
case "other":
Console.WriteLine("other...");
goto default; //goto label
default:
Console.WriteLine("x");
break;
}
try – finally
無論如何都會執行finally,所以適合用於釋放資源。
try
{
return; //即使return,仍會執行finally
decimal result = i / j;
}
catch { }
finally
{
Console.WriteLine("finally");
}
Post your comments