Struct Interval
- Namespace
- ICSharpCode.Decompiler.Util
- Assembly
- ICSharpCode.Decompiler.dll
Represents a half-closed interval. The start position is inclusive; but the end position is exclusive.
public struct Interval : IEquatable<Interval>
- Implements
- Inherited Members
- Extension Methods
Remarks
Start <= unchecked(End - 1): normal interval Start == End: empty interval Special case: Start == End == int.MinValue: interval containing all integers, not an empty interval!
Constructors
Interval(int, int)
Creates a new interval.
public Interval(int start, int end)
Parameters
start
intStart position (inclusive)
end
intEnd position (exclusive). Note that it is possible to create an interval that includes int.MaxValue by using end==int.MaxValue+1==int.MinValue.
Fields
End
Gets the exclusive end of the interval.
public readonly int End
Field Value
Remarks
Note that an End of int.MinValue is a special case, and stands for an actual End of int.MaxValue+1. If possible, prefer using InclusiveEnd for comparisons, as that does not have an overflow problem.
Start
Gets the inclusive start of the interval.
public readonly int Start
Field Value
Properties
InclusiveEnd
Gets the inclusive end of the interval. (End - 1) For empty intervals, this returns Start - 1.
public int InclusiveEnd { get; }
Property Value
Remarks
Because there is no empty interval at int.MinValue, (Start==End==int.MinValue is a special case referring to [int.MinValue..int.MaxValue]), integer overflow is not a problem here.
IsEmpty
public bool IsEmpty { get; }
Property Value
Methods
Contains(int)
public bool Contains(int val)
Parameters
val
int
Returns
Equals(Interval)
public bool Equals(Interval other)
Parameters
other
Interval
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
GetHashCode()
public override int GetHashCode()
Returns
Intersect(Interval)
Calculates the intersection between this interval and the other interval.
public Interval Intersect(Interval other)
Parameters
other
Interval
Returns
ToString()
public override string ToString()
Returns
Operators
operator ==(Interval, Interval)
public static bool operator ==(Interval lhs, Interval rhs)
Parameters
Returns
operator !=(Interval, Interval)
public static bool operator !=(Interval lhs, Interval rhs)