C#布尔以外的方法不会阅读 [英] C# Boolean outside method won't read
本文介绍了C#布尔以外的方法不会阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,这可能是非常nooby,但我一直停留在它的最后3天。我有一个名为ApplyRules方法,它是使用最为频繁,所以我不能确定它里面一个布尔值,但是当我尝试将它定义的方法之外,它并没有看过。这里是我的code:
公共BOOL solvedp1 = FALSE; 公共静态无效ApplyRules()
{ 如果(Level.Rooms [0,0] .GetItem(红宝石)!= NULL
&安培; Level.Rooms [1,0] .GetItem(蓝色宝石)!= NULL
&安培; solvedp1 == FALSE)
{
Console.Clear();
Console.WriteLine(你把宝石在正确的地方。只要创业板位置,你觉得一哆嗦和温暖的感觉进入你的脚趾,并穿过你的整个身体,在房间里的异样的感觉消失了。你听到锁开锁的门尖叫,因为它打开。);
Console.WriteLine(preSS回车键继续);
Console.ReadKey();
solvedp1 = TRUE;
}
解决方案
试试这个:
//使这个静态的,所以它是你的ApplyRules()方法进行访问。
公共静态布尔solvedp1 = FALSE;公共静态无效ApplyRules()
{
如果(Level.Rooms [0,0] .GetItem(红宝石)!= NULL
&安培; Level.Rooms [1,0] .GetItem(蓝色宝石)!= NULL
&安培; solvedp1 == FALSE)
{
Console.Clear();
Console.WriteLine(你把宝石在正确的地方。只要创业板位置,你觉得一哆嗦和温暖的感觉进入你的脚趾,并穿过你的整个身体,在房间里的异样的感觉消失了。你听到锁开锁的门尖叫,因为它打开。);
Console.WriteLine(preSS回车键继续);
Console.ReadKey();
solvedp1 = TRUE;
}
}
I have a question, which might be very nooby, but I have been stuck on it for the last 3 days. I have a method called ApplyRules, which is used very frequently so I can't define a bool inside of it, but when I try to define it outside of the method, it doesn't read it. Here is my code:
public bool solvedp1 = false;
public static void ApplyRules()
{
if (Level.Rooms[0, 0].GetItem("Red Gem") != null
& Level.Rooms[1, 0].GetItem("Blue Gem") != null
& solvedp1 == false)
{
Console.Clear();
Console.WriteLine("You put the gem in its correct place. As soon as the gem is in position, you feel a shiver and a warm feeling enters your toes and passes through your whole body. The strange feeling in the room is gone. You hear a lock unlocking and a door shrieking as it opens..");
Console.WriteLine("Press enter to continue");
Console.ReadKey();
solvedp1 = true;
}
解决方案
Try this:
//Make this static so it is accessible to your ApplyRules() method.
public static bool solvedp1 = false;
public static void ApplyRules()
{
if (Level.Rooms[0, 0].GetItem("Red Gem") != null
& Level.Rooms[1, 0].GetItem("Blue Gem") != null
& solvedp1 == false)
{
Console.Clear();
Console.WriteLine("You put the gem in its correct place. As soon as the gem is in position, you feel a shiver and a warm feeling enters your toes and passes through your whole body. The strange feeling in the room is gone. You hear a lock unlocking and a door shrieking as it opens..");
Console.WriteLine("Press enter to continue");
Console.ReadKey();
solvedp1 = true;
}
}
这篇关于C#布尔以外的方法不会阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文