How to shorten a large if-else scenario?
Is there any suggestion on how to optimize, and shorten this if case:
if (secound < 10)
TimerLabel.Text = $"{Hour}:{Minute}:0{secound}";
if (Minute< 10)
TimerLabel.Text = $"{Hour}:0{Minute}:{secound}";
if (Hour < 10)
TimerLabel.Text = $"0{Hour}:{Minute}:{secound}";
if(secound <10 && Minute < 10)
TimerLabel.Text = $"{Hour}:0{Minute}:0{secound}";
if (secound < 10 && Hour < 10)
TimerLabel.Text = $"0{Hour}:{Minute}:0{secound}";
if(Minute < 10 && Hour < 10)
TimerLabel.Text = $"0{Hour}:0{Minute}:{secound}";
if(Hour < 10 && Minute < 10 && secound < 10)
TimerLabel.Text = $"0{Hour}:0{Minute}:0{secound}";
It is just one line. Use string numeric formatting
TimerLabel.Text = $"{Hour:D2}:{Minute:D2}:{secound:D2}";
The letter D (format specifier) followed by a numeric values (precision specifier) instruct the formatting code to supply enough "0" characters to fill the required space
Just use String.Format syntax
TimerLabel.Text = $"{Hour:00}:{Minute:00}:{Second:00}");