In This Article

RangeCollection Class

Provides an implementation of a collection of Range objects.

public class RangeCollection : IKeyedObject
Inheritance:
object object
Implements:
IKeyedObject

Constructors

RangeCollection(string?)

Provides an implementation of a collection of Range objects.

public RangeCollection(string? key = null)
Parameter Type Description
key string

An optional unique string key that identifies the collection instance.

Properties

Count

The number of elements contained in the collection.

public int Count { get; }

Property Value

int

this[int]

The item at the specified index.

public Range this[int index] { get; }
Parameter Type Description
index int

The index of the item to return.

Property Value

Range

Key

A unique string key that identifies the collection instance.

public string? Key { get; }

Property Value

string

Methods

BinarySearch(int)

Performs a binary search for the specified value.

public int BinarySearch(int value)
Parameter Type Description
value int

The value for which to search.

Returns

int:

The index of the specified value in the specified array, if value is found. If value is not found and value is less than one or more elements in array, a negative number which is the bitwise complement of the index of the first element that is larger than value. If value is not found and value is greater than any of the elements in array, a negative number which is the bitwise complement of (the index of the last element plus 1).

Remarks

This method should only be used if the integers in the list are guaranteed to be sorted.

Clear()

Removes all elements in this collection.

public void Clear()

Contains(int)

Returns whether the specified value is in the contained ranges.

public bool Contains(int value)
Parameter Type Description
value int

The values for which to search.

Returns

bool:

true if the specified value is in the contained ranges; otherwise, false.

CopyTo(Range[], int)

Copies the entire collection to a compatible one-dimensional Array, starting at the specified index of the target array.

public void CopyTo(Range[] array, int arrayIndex)
Parameter Type Description
array Range[]

The one-dimensional Range array that is the destination of the elements copied from the collection. The array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<Range> GetEnumerator()

Returns

IEnumerator<Range>:

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

IndexOf(int)

Returns the index of the range that contains the specified value.

public int IndexOf(int value)
Parameter Type Description
value int

The values for which to search.

Returns

int:

The index of the range that contains the specified value, or -1 if not found.

Merge(Range)

Merges the specified Range into the collection.

public Range[] Merge(Range range)
Parameter Type Description
range Range

The Range to merge.

Returns

Range[]:

The array of Range objects in which a merge was made.

OverlapsWith(Range)

Returns whether the specified Range overlaps with a Range in the list.

public bool OverlapsWith(Range range)
Parameter Type Description
range Range

The Range to examine.

Returns

bool:

true if the specified Range overlaps with a Range in the list; otherwise, false.

Unmerge(Range)

Removes any range portions that cross the specified Range.

public Range[] Unmerge(Range range)
Parameter Type Description
range Range

The Range to remove.

Returns

Range[]:

The array of Range objects in which a merge was made.

Inherited Members

Extension Methods