var stopFyon = new StopFYON();
IEnumerable<CarOnline> carOnlineData = (IEnumerable<CarOnline>)vehrep.GetCarOnlineDetail(maintainStopFactoryOrderNo.VehicleDetail).Result;
if (carOnlineData.Any())
{
stopFyon = vehtran.CreateStopFactoryOrderNo(carOnlineData, maintainStopFactoryOrderNo, lastUpdatedBy);
}
else
{
stopFyon = vehtran.CreateStopFactoryOrderNo(null, maintainStopFactoryOrderNo, lastUpdatedBy);
}
return gen.GetResponse((Int16)ResultCode.Success, (Int16)MsgType.Ok, null, vehrep.StopFactoryOrderNo(stopFyon));
I got warning error when using sonar code analysis:
remove this useless assignment to local variable
stopFyon
Don't use var
:
StopFYON stopFyon;
The reason for the warning is that you initialize the variable with the default constructor(which could theoretically be a very expensive call, at least it's confusing). But this assignment gets overridden in all branches(the if
and the else
). So it's useless.
If you would use stopFyon
before the if
the warning would also disappear.