Table of Contents

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 int

Start position (inclusive)

end int

End 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

int

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

int

Properties

InclusiveEnd

Gets the inclusive end of the interval. (End - 1) For empty intervals, this returns Start - 1.

public int InclusiveEnd { get; }

Property Value

int

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

bool

Methods

Contains(int)

public bool Contains(int val)

Parameters

val int

Returns

bool

Equals(Interval)

public bool Equals(Interval other)

Parameters

other Interval

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Intersect(Interval)

Calculates the intersection between this interval and the other interval.

public Interval Intersect(Interval other)

Parameters

other Interval

Returns

Interval

ToString()

public override string ToString()

Returns

string

Operators

operator ==(Interval, Interval)

public static bool operator ==(Interval lhs, Interval rhs)

Parameters

lhs Interval
rhs Interval

Returns

bool

operator !=(Interval, Interval)

public static bool operator !=(Interval lhs, Interval rhs)

Parameters

lhs Interval
rhs Interval

Returns

bool