In This Article

DateRange Struct

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

public readonly struct DateRange : IComparable<DateRange>, IEquatable<DateRange>
Implements:
IComparable<DateRange> IEquatable<DateRange>

Properties

Count

The number of dates contained in the range.

public int Count { get; }

Property Value

int

EndDate

The end date of this range.

public DateTime EndDate { get; }

Property Value

DateTime

StartDate

The start date of this range.

public DateTime StartDate { get; }

Property Value

DateTime

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

int:

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

bool:

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

bool:

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

bool:

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

The object to compare with the current instance.

Returns

bool:

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

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

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

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

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

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<DateTime> GetEnumerator()

Returns

IEnumerator<DateTime>:

An enumerator that can be used to iterate through the collection.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int:

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

bool:

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

ToString()

Returns the string representation of this object.

public override string ToString()

Returns

string:

The string representation of this object.

Operators

operator ==(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

bool:

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

operator >(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

bool:

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

operator !=(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

bool:

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

operator <(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

bool:

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

Inherited Members