Visual Studio Bug?

Nol*_*nar 1 c# visual-studio-2010

我遇到了一些奇怪的事情,我不确定它是否是Visual Studio中的一个错误,或者我的无知可能是在欺骗我.

我有两个私有类变量:

class MyClass
{
    private MyList<A> aList;
    private MyList<B> bList;
    [...]
Run Code Online (Sandbox Code Playgroud)

在代码的某处,我第一次使用这些变量.

    public void MyMethod()
    {
        object[] generatorOutput = Generator.Generate(args);
        aList = (MyList<A>)generatorOutput[0];
        bList = (MyList<B>)generatorOutput[1];
        [...]
Run Code Online (Sandbox Code Playgroud)

然而Visual Studio告诉我,bList是错误的:

Cannot use local variable 'bList' before it is declared.
The declaration of the local variable hides the Field 'MyNameSpace.MyClass.bList'.
Run Code Online (Sandbox Code Playgroud)

我真的不明白Visual Studio的含义.我希望bList是本地的,它应该隐藏任何东西.

如果它有帮助:bList最初被称为cList,并且MyList<C>在我决定之前,这是一个MyList<B>绰绰有余.只有在重命名变量并更改其类型后才会出现错误消息.顺便说一下,generatorOutput始终被转换为正确的类型.

那么,这是一个错误,还是我错过了一些明显的东西?我已经尝试编译代码,重写行甚至重启Visual Studio而没有成功......

Dan*_*rth 6

我假设你MyMethod继续这样:

public void MyMethod()
{
    object[] generatorOutput = Generator.Generate(args);
    aList = (MyList<A>)generatorOutput[0];
    bList = (MyList<B>)generatorOutput[1];

    // ...

    var bList = new MyList<B>();  // <---
Run Code Online (Sandbox Code Playgroud)