Convert time unit switch statement to switch expression

This commit is contained in:
Sijmen 2021-07-08 12:40:43 +02:00
parent cc0eba7042
commit 378b6a5e65
1 changed files with 8 additions and 17 deletions

View File

@ -49,24 +49,15 @@ namespace BlazorApp.Data
continue;
}
switch (c)
timeSpan += c switch
{
case 'W':
timeSpan += TimeSpan.FromDays(value * 7);
break;
case 'D':
timeSpan += TimeSpan.FromDays(value);
break;
case 'H':
timeSpan += TimeSpan.FromHours(value);
break;
case 'M':
timeSpan += TimeSpan.FromMinutes(value);
break;
case 'S':
timeSpan += TimeSpan.FromSeconds(value);
break;
}
'W' => TimeSpan.FromDays(value * 7),
'D' => TimeSpan.FromDays(value),
'H' => TimeSpan.FromHours(value),
'M' => TimeSpan.FromMinutes(value),
'S' => TimeSpan.FromSeconds(value),
_ => throw new ArgumentOutOfRangeException($"Invalid time unit {c}")
};
value = 0;
}