1
protected async Task HandleValidSubmit()
{
     Mapper.Map(EditEmployeeModel, Employee);

     Employee result = null;

     if (Employee.EmployeeId != 0)
     {
         result = await EmployeeService.UpdateEmployee(Employee);
     }
     else
     {
         result = await EmployeeService.CreateEmployee(Employee);
     }
     if (result != null)
     {
         NavigationManager.NavigateTo("/");
     }
  }

I get a message: IDE0059 Unnecessary assignment of a value to 'result'

How can I solve this problem?

Mureinik
  • 297,002
  • 52
  • 306
  • 350
HarryM
  • 21
  • 3

1 Answers1

2

Both branches of the if and the else assign a value to result, so you don't need to initialize it with null. This null is never read and will just be overwritten anyway.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 1
    ... and unnecesary assignments can hide errors when you for instance later change that if/else. – H H Sep 20 '20 at 15:33