C# &引用;“未使用变量”;在C中使用常量时#
我一直在做一个文本冒险游戏,我有这些常量,其中包含玩家可以使用的命令。 例如:C# &引用;“未使用变量”;在C中使用常量时#,c#,constants,unused-variables,C#,Constants,Unused Variables,我一直在做一个文本冒险游戏,我有这些常量,其中包含玩家可以使用的命令。 例如: const string ConScenChoiceOne = "hit monkey talk to monkey suicide go inside"; string conchoice1; Console.WriteLine("You arrive at a temple dedicated to the monkey god."); Console.WriteLine("Outside is a monk
const string ConScenChoiceOne = "hit monkey talk to monkey suicide go inside";
string conchoice1;
Console.WriteLine("You arrive at a temple dedicated to the monkey god.");
Console.WriteLine("Outside is a monkey, presumably guarding the place.");
Console.WriteLine("What do you do?");
Console.Write(">");
conchoice1 = Console.ReadLine();
if (conchoice1.Contains("hit monkey"))
有没有办法让“变量未使用”的事情消失?我无法编辑它,因为它是一个常量。您可以取消显示此警告: 1-由
pargma
将这一行放在类文件的顶部:
#pragma warning disable 0169
2-按项目设置
(您需要的警告代码是0169)删除带有常量变量的行时,警告将消失。无论如何,您都不会在任何地方使用它。请使用变量或删除它…注释掉该行,直到您需要它为止?虽然您可以抑制警告,但在这种情况下,您为什么要这样做?OP没有在代码中使用该变量,它是多余的,因此可以删除。@DarrenDavies该怎么做由他决定。但他在问如何抑制它,他在问如何让它消失。由他决定他们如何处理该消息,但是OP可能不理解该消息的实际含义(即,没有意识到该变量已声明但从未使用)。有一个更好的解决方案,在这种情况下,删除变量或注释它,直到代码中需要它。谢谢