且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么没有警告这个未使用的变量提供?

更新时间:2022-12-22 16:38:59

原来,当赋值操作的右手边是不是编译时间常数此警告被抑制。

It turns out that this warning is suppressed when the right-hand-side of the assignment operation is not a compile-time constant.

微软解释说那是因为他们有很多的投诉,谁被分配变量纯属这样他们就可以看到调试过程中有什么返回的方法调用的人,找到了报警刺激性:

Microsoft explain that it's because they had lots of complaints from people who were assigning variables purely so they could see what a method call returned during debugging, and found the warning irritating:

已分配但从未使用,在这种情况下,
警告被反馈谁做到这一点的用户激励的抑制:

The suppression of the "assigned but never used" warning in this case was motivated by feedback from users who do this:

int Blah(){
    // blah
    BlahBlah(x, y, z)
    // blah
    // blah
}

嘿,用户说我在调试,想知道BlahBlah是
回来?但有研究在
调试器的返回值没有简单的方法,让用户非常频繁做到这一点:

"Hey," says the user while debugging, "I wonder what BlahBlah is returning?" But there is no easy way to examine the return value in the debugger, so users very frequently do this:

int Blah()
{
    // blah
    int temp = BlahBlah(x, y, z)
    // blah
    // blah
}

然后用当地人或观看窗口来检查温度。临时为
从未使用过其他地方的功能,所以它产生的刺激性
分配,但不读的警告。

and then use the locals or watch window to examine temp. The temp is never used anywhere else in the function, so it produced an irritating "assigned but not read" warning.

我觉得这是因为有点羞愧:

I think this is a bit of a shame since:


  1. 其实我觉得这些警告有帮助,当他们在MonoDevelop中给出

  2. 任何人都可以抑制警告自己(当然他们会还可以抑制未使用的编译时间常数分配的那些 - 也许应该有一个单独的警告?)。 LI>

无论如何,我明白,你不能取悦所有人。

Anyway, I understand that you can't please everyone.