gpt4 book ai didi

declaration - 在 x++ 中声明后真的需要分号吗?

转载 作者:行者123 更新时间:2023-12-04 02:38:21 26 4
gpt4 key购买 nike

正如书中所说 Microsoft Dynamics AX 2009 编程:入门 需要在 x++ 中的声明后放置分号:

The extra semicolon after the variable declaration is mandatory as long as the first line of code is not a keyword. The semicolon tells the compiler that variable declarations have come to an end. You cannot declare new variables after this semicolon.



(直接从书中复制,不变,如果需要我会删除它)

但是,当我删除分号并运行作业时,绝对没有错误或问题:
static void Job1(Args _args)
{
str string1 = "STACKOVERFLOW";
;
print string1;
pause;
}

就像
static void Job2(Args _args)
{
str string1 = "STACKOVERFLOW";

print string1;
pause;
}

真的需要吗?我应该习惯使用它吗?

最佳答案

它的解释相当优雅here .
一个关键引述[强调我的]:

"The reason you need that extra semicolon is because the compiler can’t always see where the variable declarations end. If you don’t help a little, it will make a guess. And it’s not very good at guessing."

While the compiler is analyzing the code it checks if the first word on a line matches the name of a type (AOT object). If it’s a type name the compiler treats the line as a variable declaration. In this case a variable name should be next.

关于declaration - 在 x++ 中声明后真的需要分号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1976080/

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