没有"已分配变量但从未使用过"警告

asy*_*ync 12 c#

我有以下C#代码,我正在使用VS 2012,我的所有警告都被视为错误(尽管这可能没有多大关联).

private static readonly int MAX_RADIUS_KM = 16;

private void Test() {
    int i = 2 * MAX_RADIUS_KM;
    int i2 = 2;
}
Run Code Online (Sandbox Code Playgroud)

"分配了变量[x],但从未使用过它的值" i2,但不是i.为什么?这是一个错误或幕后发生的事情吗?我会对后者感到惊讶,但如果是这样的话,那么i为避免这种警告会发生什么?

以下还显示未发出未使用的警告i:

private void Test(int foo) {
    int i = 2 * foo;
    int i2 = 2;
}
Run Code Online (Sandbox Code Playgroud)

另一个(i2在这种情况下):

private void Test()
{
  int i = 2 * 3;
  int i2 = i;
}
Run Code Online (Sandbox Code Playgroud)