Home > database >  Resharper warning
Resharper warning

Time:09-07

Resharper gives a warning value assigned is not used in any execution path

private string FindMyId(string user, string defId) => 
    defId = string.IsNullOrEmpty(defId) ? "defaultvalue" : defId;

I created above method to check if a value is empty and assign a default value to it anf return value in the same variable.It works functionaly. But it gives a message from resharper.

CodePudding user response:

"value assigned is not used in any execution path"

Well, yeah. You reassign the parameter variable defId, but because there is only one statement in the method, there's no later method statement to read that saved value. In addition, because the defId parameter is not pass by ref, that change is only scoped to the method itself.

To get rid of the warning, just remove the variable assignment.

private string FindMyId(string defId) => 
    string.IsNullOrEmpty(defId) ? "defaultvalue" : defId;

As posted, there's no use for the user parameter, and the method name FindMyId doesn't make logical sense for what the method is doing.

  • Related