What variable should I use if I want to save time values?
I want to make an app that adds 1 minutes and 25 seconds to a TimeLeft variable.
Problem is I have no idea what type of variable this should be, or even how to add 1 minutes 25 seconds to the availab开发者_StackOverflow社区le time left.
Any guidance would be much appreciated. I'm good with C#, but since I've never done something like, I'm in the dark.
I would suggest you use a DateTime
variable. This will let you manipulate the time. If you want to add 1m 25s to a varible, you could simply use:
DateTime newTime = DateTime.Now.AddSeconds(85);
That will add 85 seconds onto the current time (or, in your case, TimeLeft
as long as the TimeLeft variable is also a DateTime type)
TimeSpan
works well. It's specifically designed to hold a duration of time.
Use the DateTime type. Assuming your TimeLeft variable is an integer, you probably need to convert it to DateTime type first and then perform the add. More information here
精彩评论