简单的问题,但真的很好。当我使用它时,为什么Visual Studio社区2017标记我的大部分bool绿色的全球声明?我可能会失望:/!我尝试卸载并重新安装。没有工作。
bool bMainCharacterYUKONIdleFacingRight = true;
bool bMainCharacterYUKONIdleFacingLeft = false; // This one is marked in green
bool bMainCharacterYUKONWalkUp = false; // This one is marked in green
bool bMainCharacterYUKONWalkDown = false; // This one is marked in green
bool bMainCharacterYUKONWalkLeft = false; // This one is marked in green
bool bMainCharacterYUKONWalkRight = false; // This one is marked in green
[...]
我在这里使用那些bool动画功能:
private void AnimatingMainCharacterYUKONWalkDown()
{
switch (iFrameCounter)
{
case 1:
pbMainCharacterYUKON.Image = Properties.Resources.Walk__1_;
break;
case 2:
pbMainCharacterYUKON.Image = Properties.Resources.Walk__2_;
break;
case 3:
pbMainCharacterYUKON.Image = Properties.Resources.Walk__3_;
break;
case 4:
pbMainCharacterYUKON.Image = Properties.Resources.Walk__4_;
break;
case 5:
pbMainCharacterYUKON.Image = Properties.Resources.Walk__5_;
break;
}
iFrameCounter++;
pbMainCharacterYUKON.Top = pbMainCharacterYUKON.Top + 12;
if (iFrameCounter > 5)
{
bMainCharacterYUKONIdleFacingRight = true;
bMainCharacterYUKONIdleFacingLeft = false;
bMainCharacterYUKONWalkUp = false;
bMainCharacterYUKONWalkDown = false;
bMainCharacterYUKONWalkRight = false;
bMainCharacterYUKONWalkLeft = false;
}
谢谢!
答案 0 :(得分:2)
这些变量没有加下划线,因为你没有“使用”它们 - 它们被加下划线,因为你从未读过它们。你的代码演示了声明bool,然后设置了它们的值,但它从未证明你读过它们的值。
答案 1 :(得分:1)
只是添加到dynamichael的答案......
"阅读"变量是使它出现在等号的右侧(即在赋值语句的右侧),例如,
bool newBool = bMainCharacterYUKONIdleFacingLeft;
或,在表达式中使用它,例如
if (bMainCharacterYUKONIdleFacingLeft == true)
{
// do stuff
}
这两个都涉及变量" read"