>
>
>
V3085. The name of 'X' field/property i…


V3085. The name of 'X' field/property in a nested type is ambiguous. The outer type contains static field/property with identical name.

The analyzer detected that a nested class contains a field or property with the same name as a static/constant field or property in the outer class.

Consider the following example:

class Outside
{
  public static int index;
  public class Inside
  {
    public int index; // <= Field with the same name
    public void Foo()
    {
      index = 10;
    }
  }
}

A construct like that may result in incorrect program behavior. The following scenario is the most dangerous. Suppose that there was no 'index' field in the 'Inside' class at first. It means that it was the static variable 'index' in the 'Outside' class that the 'Foo' function used to change. Now that we have added the 'index' field to the 'Inside' class and the name of the outer class is not specified explicitly, the 'Foo' function will be changing the 'index' field in the nested class. The code, naturally, will start working differently from what the programmer expected, although it won't trigger any compiler warnings.

The error can be fixed by renaming the variable:

class Outside
{
  public static int index;
  public class Inside
  {
    public int insideIndex;
    public void Foo()
    {
      index = 10;
    }
  }
}

You can look at examples of errors detected by the V3085 diagnostic.