我有一些代码,我认为应该生成一个'已分配,但它的值从未使用过'警告:
public void SomeFunction(ISomeInterface instance)
{
ISomeInterface localReference = instance;
//... localReference is never mentioned again
}
但是,它根本没有产生警告。在函数内部创建也是如此:
public void SomeFunction()
{
ISomeInterface localReference = new SomeInterfaceImplementation();
//..localReference never mentioned again
}
这些都不会产生警告,而是在j
处生成警告:
public void SomeFunction(ISomeInterface instance, int i)
{
int j = o;
ISomeInterface localReference = instance;
//... neither localReference nor j is mentioned again
}
为什么不使用的对象会产生警告?即使赋值有副作用(可能来自第一个例子的隐式转换),变量本身仍未使用,当然应该生成警告?