CSharp examples for System:DateTime Day
For a given range of dates increments starting date by one day up to final date, calling specified action with each iteration.
using System.Globalization; using System;// w w w .j av a 2 s .co m public class Main{ /// <summary> /// <para>For a given range of dates increments starting date by one day up to final date, calling specified action with each iteration.</para> /// </summary> /// <param name="self">Starting date to increment.</param> /// <param name="to">Final date to increment 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 UpTo(this DateTime self, DateTime to, Action action) { Assertion.NotNull(action); to.Subtract(self).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); } }