本文介绍了IDE0059不必要地将值分配给“结果"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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("/");
     }
  }


我收到一条消息:IDE0059不必要地将值分配给结果"


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

我该如何解决这个问题?

How can I solve this problem?

推荐答案

if else 的两个分支都将一个值分配给 result ,因此您无需使用 null 对其进行初始化.此 null 不会被读取,无论如何只会被覆盖.

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.

这篇关于IDE0059不必要地将值分配给“结果"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 05:32