Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;“未使用变量”;在C中使用常量时#_C#_Constants_Unused Variables - Fatal编程技术网

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可能不理解该消息的实际含义(即,没有意识到该变量已声明但从未使用)。有一个更好的解决方案,在这种情况下,删除变量或注释它,直到代码中需要它。谢谢