if (!this._contextAccessor.HttpContext?.Request.RouteValues.TryGetValue("requiredId", out
var idRouteParam) ?? true)
return Task.CompletedTask;
var id = (int)idRouteParam;
I figured by the time it got to the cast everything would work but I keep getting this compiler error "Local variable 'idRouteParam' might not be initialized before accessing" and cant figure out why
I would suspect that this is a limitation of definite assignment analysis in the compiler, however only minor adjustment is required to get it to compile, here are a couple of options you could choose from:
Compare with Boolean:
Bracket to perform the null-coalesce before the
!:With either of the above changes the compiler is able to determine that
idRouteParamis always assigned before use.