在 C# 中,您可以创建这样的实例:
Custom mycustomelement = new Custom { ElenentName = "My Custom Element" };
Run Code Online (Sandbox Code Playgroud)
我想知道如何在 Visual Basic 中创建这样的实例以及这种类型的创建实例的名称。
import time
def countdown(time_sec):
while time_sec:
mins, secs = divmod(time_sec, 60)
timeformat = "{:02d}:{:02d}".format(mins, secs)
print(timeformat, end='\r')
time.sleep(1)
time_sec -= 1
print("Time ended.")
Run Code Online (Sandbox Code Playgroud)
您在上面看到的这段 Python 代码运行顺利,并从给定的 开始倒计时time_sec。此代码还每秒清洁屏幕。我想编写在 Ruby 中工作完全相同的代码。
#timer.rb(Ruby codes) here
def countdown time_sec
while time_sec
mins, secs = time_sec.divmod(60)[0], time_sec.divmod(60)[1]
timeformat = "%02d:%02d" % [mins, secs]
puts "#{timeformat}\r"
sleep(1)
time_sec -= 1
end
puts "Time is ended."
end
Run Code Online (Sandbox Code Playgroud)
您在上面看到的这段 Ruby 代码以错误的方式工作。首先,秒数被依次打印。但我想像上面的 Python 代码一样更新单行。其次,当运行此 Ruby 代码并达到倒计时时00:00,它会继续从 开始倒计时-01:59。我该如何更正此代码?