变量已分配但从未使用其值 (C#)

sun*_*r s -3 c# winrt-xaml

在 Visual Studio 中,我使用了以下代码:

 private bool answer = true;
    Private Buttonclick()
   {
      if()
       {
        answer =false
        }
   }
Run Code Online (Sandbox Code Playgroud)

编译器给我一个警告,说“已分配答案,但从未使用过它的值”。我该如何解决?

小智 5

这意味着您已经给出answer了一个值,但没有在其他地方引用它。这意味着您没有在程序的其他地方使用答案。

您可以通过引用程序另一部分的答案来修复它。