gpt4 book ai didi

c# - C# 和 C++ 中 switch 语句的区别

转载 作者:IT老高 更新时间:2023-10-28 22:23:55 24 4
gpt4 key购买 nike

我刚开始自学 C#,在关于 Switch 语句的教程中,我读到:

The behavior where the flow of execution is forbidden from flowing from one case block to the next is one area in which C# differs from C++. In C++ the processing of case statements is allowed to run from one to another.

为什么它在 C# 中的一个 case 语句之后停止?如果您可以使用 break 语句在任何时候停止,那么在 C# 与 C++ 中是否有任何理由在找到匹配项后让它停止?如果你想在 C# 中使用多个 case,是否必须使用另一个 Switch 语句?

最佳答案

C# 有 goto casevalue,它具有 fallthrough 的所有好处,但更难偶然发生。

Example on MSDN

关于c# - C# 和 C++ 中 switch 语句的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13239912/

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