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.
EndDate
The end date of this range.
StartDate
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
- 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
otherparameter. Zero means this object is equal toother. Greater than zero means this object is greater thanother.
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:
trueif 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:
trueif 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:
trueif the current object is equal to theotherparameter; 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:
trueifobjand 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
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
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
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
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
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:
trueif the specified date range overlaps with, or crosses, this range; otherwisefalse.
ToString()
Returns 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
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
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
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. |