gpt4 book ai didi

c# - switch 语句中的这个变量如何在没有声明的情况下看似使用?

转载 作者:行者123 更新时间:2023-11-30 15:02:18 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
C# switch variable initialization: Why does this code NOT cause a compiler error or a runtime error?

在这个 switch 语句中(令我惊讶的是编译和执行没有错误),变量 something 没有在情况 2 中声明,并且情况 1 永远不会执行。这怎么有效?变量 something 不声明怎么用?

switch(2){
case 1:
string something = "whatever";
break;
case 2:
something = "where??";
break;
}

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