CSharp examples for System:DateTime Day
For a given range of dates decrements starting date by one day down to final date, calling specified action with each iteration.
using System.Globalization; using System;//from w w w . j a v a2s.c o m public class Main{ /// <summary> /// <para>For a given range of dates decrements starting date by one day down to final date, calling specified action with each iteration.</para> /// </summary> /// <param name="self">Starting date to decrement.</param> /// <param name="to">Final date to decrement to.</param> /// <param name="action">Delegate to call on each step of iteration.</param> /// <returns>Back reference to <paramref name="self"/> instance.</returns> /// <exception cref="ArgumentNullException">If <paramref name="action"/> is a <c>null</c> reference.</exception> public static DateTime DownTo(this DateTime self, DateTime to, Action action) { Assertion.NotNull(action); self.Subtract(to).Days.Times(action); return self; } /// <summary> /// <para>Creates a time span object, representing a given number of days.</para> /// </summary> /// <param name="self">Number of days.</param> /// <returns>Time span instance.</returns> public static TimeSpan Days(this int self) { return new TimeSpan(self, 0, 0, 0); } /// <summary> /// <para>Creates a time span object, representing a given number of days.</para> /// </summary> /// <param name="self">Number of days.</param> /// <returns>Time span instance.</returns> public static TimeSpan Days(this short self) { return new TimeSpan(self, 0, 0, 0); } /// <summary> /// <para>Creates a time span object, representing a given number of days.</para> /// </summary> /// <param name="self">Number of days.</param> /// <returns>Time span instance.</returns> public static TimeSpan Days(this byte self) { return new TimeSpan(self, 0, 0, 0); } }