In my code, I have the following code:
Order = config.DeploymentSteps.Select(x => x.Order).DefaultIfEmpty().Max() + 1;
This gives me Cannot implicitly convert type 'int' to 'short' error Cannot implicitly convert type 'int' to 'short' . As references, Order and x.Order are both shorts, and Max() correctly returns a short (I checked this). Therefore, I realized that 1 is integer and error. So I changed it to:
Order = config.DeploymentSteps.Select(x => x.Order).DefaultIfEmpty().Max() + (short)1;
Now I still get the same compiler. So maybe this is not the right solution, so I tried changing it to
Order = config.DeploymentSteps.Select(x => x.Order).DefaultIfEmpty().Max() + Convert.ToInt16(1);
But I still get the same error. Finally, I got it to work, converting the entire expression:
Order = Convert.ToInt16(config.DeploymentSteps.Select(x => x.Order).DefaultIfEmpty().Max() + 1);
Why can't I put 1 to a short and add it to another short without dropping it all?
source share