Why is the data type of System.Timers.Timer.Interval a double?
.net, c#, timer
Solution
Disassembling shows that the interval is consumed via a call to `(int)Math.Ceiling(this.interval)` so even if you were to specify a real number, it would be turned into an `int` before use. This happens in a method called `UpdateTimer`.
Why? No idea, perhaps the spec said that `double` was required at one point and that changed? The end result is that `double` is not strictly required, because it is eventually converted to an `int` and cannot be larger than `Int32.MaxValue` according to the docs anyway.
Yes, the timer can "support" real numbers, it just doesn't tell you that it silently changed them. You can initialise and run the timer with `100.5d`, it turns it into `101`.
And yes, it is all a bit daft: 4 wasted bytes, potential implicit casting, conversion calls, explicit casting, all needless if they'd just used `int`.
Problem
This is a bit of an academic question as I'm struggling with the thinking behind Microsoft using double as the data type for the Interval property! Firstly from MDSN Interval is the time, in milliseconds, between Elapsed events; I would interpret that to be a discrete number so why the use of a double? surely int or long makes greater sense!? Can Interval support values like 5.768585 (5.768585 ms)? Especially when one considers System.Timers.Timer to have nowhere near sub millisecond accuracy... Most accurate timer in .NET? Seems a bit daft to me.. Maybe I'm missing something!