小编The*_*ynx的帖子

如何缩短大型if-else场景?

有没有关于如何优化的建议,并在以下情况下缩短:

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}";
Run Code Online (Sandbox Code Playgroud)

c# loops

-2
推荐指数
2
解决办法
76
查看次数

标签 统计

c# ×1

loops ×1