gpt4 book ai didi

c# - 在 switch case 中哪个具有更好的性能,Enum 或 Int?

转载 作者:太空狗 更新时间:2023-10-29 22:03:38 24 4
gpt4 key购买 nike

在考虑以枚举和 int 作为 case 参数的 switch case 的性能时,使用哪个代码片段更好:

A.

switch ((ToolbarButton)BtnId)
{
case ToolbarButton.SHOWPROPERTYDIALOG:
OnShowProperties();
break;
case ToolbarButton.MOVETOFIRST:
OnFirstMessage();
break;
case ToolbarButton.MOVETOLAST:
OnLastMessage();
break;
}

B.

switch (BtnId)
{
case (int)ToolbarButton.SHOWPROPERTYDIALOG:
OnShowProperties();
break;
case (int)ToolbarButton.MOVETOFIRST:
OnFirstMessage();
break;
case (int)ToolbarButton.MOVETOLAST:
OnLastMessage();
break;
}

最佳答案

一旦编译,Enums ARE Ints

在 MSIL 中没有任何区别。

关于c# - 在 switch case 中哪个具有更好的性能,Enum 或 Int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11516540/

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