Compiler Warning (level 3) CS1717
Assignment made to same variable; did you mean to assign something else?
This warning occurs when you assign a variable to itself, such as a = a
.
Several common mistakes can generate this warning:
Writing
a = a
as the condition of an if statement, such asif (a = a)
. You probably meant to sayif (a == a)
, which is always true, so you could write this more concisely asif (true)
.Mistyping. You probably meant to say
a = b
.In a constructor where the parameter has the same name as the field, not using the this keyword: you probably meant to say
this.a = a
.
Example
The following sample generates CS1717.
// CS1717.cs
// compile with: /W:3
public class Test
{
public static void Main()
{
int x = 0;
x = x; // CS1717
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.