Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I was wondering what is exactly the value of gameTime.ElapsedGameTime.TotalSeconds in a second?
gametime.ElapsedGameTime returns the time elapsed since the last update, not the total game time. For this, you need gametime.TotalGameTime.
It is returned as a TimeSpan, so the last part (TotalSeconds) is a property of that struct. Since it's a TimeSpan, you have full access to other properties, like TotalMilliseconds or methods like Compare.
And since TotalSeconds is a double, it will indeed be 0.5 if the elapsed time is 500 milliseconds.
If the game is running at 60 frames per second the value is likely to be 1 / 60 = 0.0166 seconds.
gameTime.ElapsedGameTime.TotalSeconds, as the name suggests, is the total number of seconds your game has been running. So if your game has been running for 1 second then this will be equal to 1. If your game has been running for a minute then this will be equal to 60.
Is there more to your question?
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
i have typed this code and ran it , and it runs infinitely , i couldn't understand why since it should have stopped once x gets to 10
i expected it to stop at 10 since it started from 0 and incremented by 1 until it gets to 10
for loops do not have an exit condition. They have a continue condition. When the middle condition is tested, the loop continues if it is true. x = 10 is an assignment expression. It assigns 10 to x, and the value of the assignment expression is the new value of x, so it is always 10 (or, if x is a _Bool, it is 1), which serves as “true” for the condition. You may have wanted x == 10, which is a comparison expression. But that is true only when x is 10, so the loop would never execute even the first iteration. You need to a condition to continue the loop, not to exit it, so you want x < 10.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Here is the code I am using. It seems simple but the number it returns is incorrect:
var a = DateTime.Now;
var b = new DateTime(1970, 1, 1);
var c = a.Subtract(b);
var d = c.Milliseconds;
return d;
Does anyone have any suggestions as to what I am doing wrong?
The Milliseconds property gives you the milliseconds component of the time span (in other words, the millisecond-of-second), not the total number of milliseconds in the timespan. Its magnitude will always be less than 1000, since it's how many milliseconds are left when you have taken all the whole seconds away from the time span.
For what you want, use TotalMilliseconds.
You have to use c.TotalMilliseconds instead of c.Milliseconds;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Can anybody tell me what is the difference between these two functions in C#? TotalDays and Days because I'm not sure which once I should use in my code? Sorry for the low information on this text, but there is not much I can talk about.
Since i haven't found a duplicate i post my comment here:
Always read the documentation first. TotalDays is a double because it represents whole and fractional days whereas Days is an int which represents only whole days.
That is even mentioned explicitly in the remarks sections of TimeSpan.Days/TotalDays:
The Days property represents whole days, whereas the TotalDays
property represents whole and fractional days.
One thing to note, as opposed to the other properties in TimeSpan like Hours/TotalHours there is no limit on Days. So it doesn't end with 30 or 365(like Hour which ranges from -23 through 23) since there is no larger unit than year. So Days will always be the same number as (int) ts.TotalDays.
A TimeSpan doesn't have a sensible concept of "years" because it
depends on the start and end point. (Months is similar - how many
months are there in 29 days? Well, it depends...) [J. Skeet]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I have a Task to do C#. I need to add two numbers.
The first number contains around 100 digits like "12822429847264872649624264924626466826446692............"
and second number also with 100 digits or more or less
by using this numbers i need task like add/sub/multiply/div
I done this using BigInteger in C#
But do I need to do this using arrays or strings?
Since they are both 100 digits just start with the last digit and in a for loop just add each one, but if the value is > 10 then remember to add one to the next digit.
This is how children learn to add, you just need to follow the same steps, but the answer should be in an array of 101 characters.
UPDATE:
Since you have shown some code now, it helps.
First, don't duplicate the code based on if str1 or str2 is larger, but make a function with that logic and pass in the larger one as the first parameter.
Determine the largest size and make certain the smaller value is also the same size, to make math easier.
The smaller one should have leading zeroes (padding), again to help keep the code simple.
You can also start by looking at the source code for structures such as BigInteger. They would provide you more insight into aspects such as computational efficiency and storage, particularly about multiplication and division. You can take a look at here or here.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Let's suppose I have an interval. Say 15 minutes.
I have a start time of 13:57 and an end time of 15:17.
The time when this process runs happens to be 14:07.
I want the result to be 14:00,14:15,14:30,14:45,15:00,15:15 while retaining the year/month/date, etc.
So far, I have these facts down. The minutes modulo the interval is always zero. I need to count down from the current time until I hit the first mod-zero number which is 14:00.
I then simply increase that number by the interval until I reach my ceiling. My real question is how to come up with an elegant, simple way to find this first floor number.
The interval is a timespan and the other two values are datetimes.
Any ideas?
You can calculate the minute for the first result instance like:
m: current time's minute
new minute part: m - (m % interval)