Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V3228. It is possible that an...
menu mobile close menu
Additional information
toggle menu Contents

V3228. It is possible that an assigned variable should be used in the next condition. Consider checking for misprints.

Nov 26 2025

The analyzer has detected a potential error where a variable with a similar name is checked instead of the intended one.

The example:

bool UserProcessing()
{
  ....
  var user1 = FindUser(id1);

  if (user1 == null)
    return false;
  ....
  var user2 = FindUser(id2);

  if (user1 == null)
    return false;
  ....
}

In the example, two variables with similar names, user1 and user2, are initialized. After initialization, the value of each variable should be checked for null. However, due to a typo in the second if condition, the user2 variable will not be checked.

The fixed code:

bool UserProcessing()
{
  ....
  var user1 = FindUser(id1);

  if (user1 == null)
    return false;
  ....
  var user2 = FindUser(id2);

  if (user2 == null)
    return false;
  ....
}

Another example:

private readonly int _value;
....
public CustomType(int value)
{
  ....
  _value = value < 0 ? 0 : value;

  if (value == 0) { .... }
  ....
}

The _value field is assigned the value parameter that is limited to positive values. Instead of validating the field, the parameter is checked for 0, which may still have a negative value.

The fixed code:

private readonly int _value;
....
public CustomType(int value)
{
  ....
  _value = value < 0 ? 0 : value;

  if (_value == 0) { .... }
  ....
}