In This Article

DateRange Struct

Represents a date range, which is an inclusive pair of DateTime objects representing dates.

public struct DateRange : IComparable<DateRange>, IEnumerable<DateTime>, IEnumerable, IEquatable<DateRange>
Implements:
IComparable<DateRange> IEquatable<DateRange>

Properties

Count

Gets the number of dates contained in the range.

public int Count { get; }

Property Value

Int32:

The number of dates contained in the range.

EndDate

Gets the end date of this range.

public DateTime EndDate { get; }

Property Value

DateTime:

The end date of this range.

StartDate

Gets the start date of this range.

public DateTime StartDate { get; }

Property Value

DateTime:

The start date of this range.

Methods

CompareTo(DateRange)

Compares the current object with another object of the same type.

public int CompareTo(DateRange other)
Parameter Type Description
other DateRange

An object to compare with this object.

Returns

Int32:

A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings: Less than zero means this object is less than the other parameter. Zero means this object is equal to other. Greater than zero means this object is greater than other.

Contains(DateRange)

Determines whether the specified date range is contained in this range.

public bool Contains(DateRange dateRange)
Parameter Type Description
dateRange DateRange

The date range.

Returns

Boolean:

true if the specified date range is contained in this range; otherwise, false.

Contains(DateTime)

Determines whether the specified date is contained in this range.

public bool Contains(DateTime date)
Parameter Type Description
date DateTime

The date to examine.

Returns

Boolean:

true if the specified date is contained in this range; otherwise, false.

Equals(DateRange)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(DateRange other)
Parameter Type Description
other DateRange

An object to compare with this object.

Returns

Boolean:

true if the current object is equal to the other parameter; otherwise, false.

Equals(Object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)
Parameter Type Description
obj Object

Another object to compare to.

Returns

Boolean:

true if obj and this instance are the same type and represent the same value; otherwise, false.

FromDate(DateTime)

Gets a date range for specified single date.

public static DateRange FromDate(DateTime date)
Parameter Type Description
date DateTime

The start date.

Returns

DateRange:

A date range for the specified single date.

FromDecade(DateTime)

Gets a date range for the decade that contains the specified date.

public static DateRange FromDecade(DateTime date)
Parameter Type Description
date DateTime

The date.

Returns

DateRange:

A date range for the decade that contains the specified date.

FromMonth(DateTime)

Gets a date range for the month that contains the specified date.

public static DateRange FromMonth(DateTime date)
Parameter Type Description
date DateTime

The date.

Returns

DateRange:

A date range for the month that contains the specified date.

FromRange(DateTime, DateTime)

Gets a date range for specified range.

public static DateRange FromRange(DateTime startDate, DateTime endDate)
Parameter Type Description
startDate DateTime

The start date.

endDate DateTime

The end date.

Returns

DateRange:

A date range for the specified range.

FromYear(DateTime)

Gets a date range for the year that contains the specified date.

public static DateRange FromYear(DateTime date)
Parameter Type Description
date DateTime

The date.

Returns

DateRange:

A date range for the year that contains the specified date.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<DateTime> GetEnumerator()

Returns

IEnumerator<DateTime>:

A IEnumerator<T> that can be used to iterate through the collection.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

Int32:

A 32-bit signed integer that is the hash code for this instance.

OverlapsWith(DateRange)

Determines whether the specified date range overlaps with, or crosses, this range.

public bool OverlapsWith(DateRange otherRange)
Parameter Type Description
otherRange DateRange

The date range to examine.

Returns

Boolean:

true if the specified date range overlaps with, or crosses, this range; otherwise false.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

String:

A String containing a fully qualified type name.

Operators

Equality(DateRange, DateRange)

Compares two DateRange objects to determine whether they are equal.

public static bool operator ==(DateRange left, DateRange right)
Parameter Type Description
left DateRange

The left.

right DateRange

The right.

Returns

Boolean:

true if both DateRange objects are equal; otherwise, false.

GreaterThan(DateRange, DateRange)

Compares two DateRange objects to determine whether the first instance is greater than the second instance.

public static bool operator>(DateRange left, DateRange right)
Parameter Type Description
left DateRange

The left.

right DateRange

The right.

Returns

Boolean:

true if the first DateRange is less greater the second DateRange; otherwise, false.

Inequality(DateRange, DateRange)

Compares two DateRange objects to determine whether they are not equal.

public static bool operator !=(DateRange left, DateRange right)
Parameter Type Description
left DateRange

The left.

right DateRange

The right.

Returns

Boolean:

true if both DateRange objects are not equal; otherwise, false.

LessThan(DateRange, DateRange)

Compares two DateRange objects to determine whether the first instance is less than the second instance.

public static bool operator <(DateRange left, DateRange right)
Parameter Type Description
left DateRange

The left.

right DateRange

The right.

Returns

Boolean:

true if the first DateRange is less than the second DateRange; otherwise, false.

Inherited Members