Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V3005. The 'x' variable is assigned...
menu mobile close menu
Additional information
toggle menu Contents

V3005. The 'x' variable is assigned to itself.

Dec 14 2015

The analyzer has detected a potential error: a variable is assigned to itself.

The real-world code example:

public GridAnswerData(
  int questionId, int answerId, int sectionNumber,  
  string fieldText, AnswerTypeMode typeMode)
{
  this.QuestionId = this.QuestionId;
  this.AnswerId = answerId;
  this.FieldText = fieldText;
  this.TypeMode = typeMode;
  this.SectionNumber = sectionNumber;
}

The values of an object's properties are intended to be changed according to the method parameters, but mistakenly assigned its own value to the QuestionId property instead of the questionId argument's value.

The fixed code:

public GridAnswerData(
  int questionId, int answerId, int sectionNumber,  
  string fieldText, AnswerTypeMode typeMode)
{
  this.QuestionId = questionId;
  this.AnswerId = answerId;
  this.FieldText = fieldText;
  this.TypeMode = typeMode;
  this.SectionNumber = sectionNumber;
}

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