In my code i have the following code:
Order = config.DeploymentSteps.Select(x => x.Order).DefaultIfEmpty().Max() + 1;
This gives me the error Cannot implicitly convert type 'int' to 'short'
. As a Reference Order
and x.Order
are both shorts, and Max()
is correctly returning a short
(I have verified this). So I get it, it thinks the 1
is an integer
and erroring. So I changed it to:
Order = config.DeploymentSteps.Select(x => x.Order).DefaultIfEmpty().Max() + (short)1;
I'm now still getting the same compile. So maybe it's not casting it right, so I tried changing it to
Order = config.DeploymentSteps.Select(x => x.Order).DefaultIfEmpty().Max() + Convert.ToInt16(1);
Yet I still get the same error. Finally I got it to work by converting the whole expression:
Order = Convert.ToInt16(config.DeploymentSteps.Select(x => x.Order).DefaultIfEmpty().Max() + 1);
Why can't I cast the 1 to a short
and add it to another short, without casting the whole thing?