SonarQube: Change this condition so that it does not always evaluate to "false"

Hi,

I can’t figure out how to fix this warning.

Change this condition so that it does not always evaluate to “true”

Using this code

 public async Task<int> UpdateAsync(int id, string comment){
.....
myCommand.Parameters.AddWithValue("@comment", !string.IsNullOrEmpty("comment") ? comment : DBNull.Value);
.....
}
  • Developer Edition
  • Version 9.2.3 (build 50713)

Hi,

Welcome to the community!

From my reading, string.IsNullOrEmpty evaluates its argument, the literal "comment" in this case, for being null or an empty string (""). Since you’ve passed in a literal, non-empty string, then it will always evaluate to false.

Perhaps you meant to use the comment parameter instead?

 
Ann

1 Like