This code compiles:
public static void SetBackLink(dynamic viewBag, NameValueCollection queryString, bool defaultToServicePage = false) {
if (defaultToServicePage && string.IsNullOrEmpty(viewBag.BackLinkUrl)) {
if (!long.TryParse(queryString["serviceId"], out long serviceId)) {
return;
}
viewBag.BackLinkUrl = UserEntityService.CalculationService.GetServicePageUrl(serviceId);
viewBag.BackLinkText = UserEntityService.CalculationService.GetServiceTitle(serviceId);
}
}
This code has compiler error Use of unassigned local variable 'serviceId' on the third line:
public static void SetBackLink(dynamic viewBag, NameValueCollection queryString, bool defaultToServicePage = false) {
if (defaultToServicePage && string.IsNullOrEmpty(viewBag.BackLinkUrl) && long.TryParse(queryString["serviceId"], out long serviceId)) {
viewBag.BackLinkUrl = UserEntityService.CalculationService.GetServicePageUrl(serviceId);
viewBag.BackLinkText = UserEntityService.CalculationService.GetServiceTitle(serviceId);
}
}
I have the following version of Visual Studio:
Microsoft Visual Studio Enterprise 2019
Version 16.4.5
VisualStudio.16.Release/16.4.5+29806.167
Microsoft .NET Framework
Version 4.8.03752
Installed Version: Enterprise
Is this a compiler bug?