DOTnet Stuff: TimeSpan Multiplication and Division
Today I was working with TimeSpan and needed to average some. I realized that TimeSpan supports Addition and Subtraction directly but no multiplication or division. Then it struck me use Ticks... Ticks are the shortest time span recognized by DotNet. to do simple multiplication or division do the following
long ticks = averageTimeSpan.Ticks/2;
averageTimeSpan = new TimeSpan(ticks);
long ticks = averageTimeSpan.Ticks/2;
averageTimeSpan = new TimeSpan(ticks);
No TrackBacks
TrackBack URL: https://blogs.psu.edu/mt4/mt-tb.cgi/198035

Leave a comment