有人可以解释为什么切换语法是这样的吗? [英] Can someone explain why switch syntax is the way it is?
本文介绍了有人可以解释为什么切换语法是这样的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不,这不是关于休息的抱怨 - 我很高兴能够明确地制作
。
然而,为什么不是格式如下:
开关(myVariable)
{
案例1:
{
//做点什么
}
案例2:
{
//做其他事情
}
默认
//什么都不做
}
这样''break''被包含在结束的大括号中,并且
它遵循与
语言确实。
Andy D
解决方案
Andrew,
这实际上并不是一个坏主意。如果您对产品
反馈网站提出建议,我会非常乐意为它投票。
-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com
" Andrew Ducker" <一个**** @ ducker.org.uk>在消息中写道
news:11 ********************* @ f14g2000cwb.googlegro ups.com ...不,这不是关于休息的抱怨 - 我很高兴能把事情弄清楚。
然而,为什么格式不是这样的:
开关(myVariable)
{
案例1:
{
//做点什么
}
案例2:
{
//做其他事情
}
默认
//什么都不做
}
这样'' 'break''被包含在结束的大括号中,并且
它遵循与
语言的其余部分相同的分组命令的方式。
Andy D
我认为原因是它可能会让它看起来更清洁一点
这样的东西:
>
开关(myVariable)
{
案例1:
案例2:
//如果myVaria做一些事情ble是1或2;
休息;
案例3:
案例4:
//做某事如果myVariable是3或4;
休息;
默认:
}
虽然,我认为如果你能做案例1,2:它会更好看。
它可能会回到C语言的根源。
Andrew Ducker写道:
不,这不是关于休息的抱怨 - 我很高兴能把事情弄清楚。
然而,为什么格式不一样:
switch(myVariable)
{
案例1:
{
//做某事
}
案例2:
//
}
默认
//什么都不做
}
这样''break''被包含在结束的大括号中,并且
它遵循与
语言的其余部分相同的分组命令的方式。 />
Andy D
老实说我更喜欢休息,它不是那么久,非常清楚
使用,
如果C人看到它,他知道这是期待的。
如果一个C人看到你的提议,那么它是不明确的。
也可以对于编译器编写者来说它更容易,在你的情况下取决于
,其中}}被发现它意味着不仅仅是一个结束语境。
我更喜欢它的方式现在是:)
欢呼,
-
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
佛罗里达州交通局
Andrew Ducker <一个**** @ ducker.org.uk>在消息中写道
news:11 ********************* @ f14g2000cwb.googlegro ups.com ...不,这不是关于休息的抱怨 - 我很高兴能把事情弄清楚。
然而,为什么格式不是这样的:
开关(myVariable)
{
案例1:
{
//做点什么
}
案例2:
{
//做其他事情
}
默认
//什么都不做
}
这样'' 'break''被包含在结束的大括号中,并且
它遵循与
语言的其余部分相同的分组命令的方式。
Andy D
And no, this isn''t a complaint about break - I''m very happy to make
things explicit.
However, why isn''t the format something like:
switch(myVariable)
{
case 1:
{
//Do Something
}
case 2:
{
//Do Something Else
}
default
// Do Nothing at all
}
That way the ''break'' is subsumed into the closing curly brackets, and
it follows the same way of grouping commands as the rest of the
language does.
Andy D
解决方案
Andrew,
It''s actually not a bad idea. If you put a suggestion on the product
feedback site, I would be more than happy to vote for it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Andrew Ducker" <an****@ducker.org.uk> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...And no, this isn''t a complaint about break - I''m very happy to make
things explicit.
However, why isn''t the format something like:
switch(myVariable)
{
case 1:
{
//Do Something
}
case 2:
{
//Do Something Else
}
default
// Do Nothing at all
}
That way the ''break'' is subsumed into the closing curly brackets, and
it follows the same way of grouping commands as the rest of the
language does.
Andy D
I think the reason is that it might make it look a little cleaner for
something like this:
switch(myVariable)
{
case 1:
case 2:
//do something if myVariable is 1 or 2;
break;
case 3:
case 4:
//do something if myVariable is 3 or 4;
break;
default:
}
Although, I think it would even look nicer if you could do "case 1, 2: ".
It probably goes back to the roots of the C language.
"Andrew Ducker" wrote:
And no, this isn''t a complaint about break - I''m very happy to make
things explicit.
However, why isn''t the format something like:
switch(myVariable)
{
case 1:
{
//Do Something
}
case 2:
{
//Do Something Else
}
default
// Do Nothing at all
}
That way the ''break'' is subsumed into the closing curly brackets, and
it follows the same way of grouping commands as the rest of the
language does.
Andy D
Hi,
Honestly I prefer the break , it not that much longer and is VERY clear
the use,
If a C person see it, he knows that to expect.
If a C person see your proposal , well it''s not explicit :)
also maybe it''s easier for the compiler writers, in your case depending of
where the } is found it means more than a closing context.
I prefer the way it''s now :)
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Andrew Ducker" <an****@ducker.org.uk> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...And no, this isn''t a complaint about break - I''m very happy to make
things explicit.
However, why isn''t the format something like:
switch(myVariable)
{
case 1:
{
//Do Something
}
case 2:
{
//Do Something Else
}
default
// Do Nothing at all
}
That way the ''break'' is subsumed into the closing curly brackets, and
it follows the same way of grouping commands as the rest of the
language does.
Andy D
这篇关于有人可以解释为什么切换语法是这样的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文