RangeCollection Class
Provides an implementation of a collection of Range objects.
public class RangeCollection
- Inheritance:
- object object
Constructors
RangeCollection()
Initializes a new instance of the RangeCollection
class.
public RangeCollection()
RangeCollection(string)
Initializes a new instance of the RangeCollection
class.
public RangeCollection(string key)
Parameter | Type | Description |
---|---|---|
key | string | A unique string key that identifies the collection instance. |
Properties
Count
Gets the number of elements contained in the collection.
this[int]
Gets the interval at the specified index.
[C#] In C#, this property is the indexer for the RangeCollection
class.
public Range this[int index] { get; }
Parameter | Type | Description |
---|---|---|
index | int | The index of the interval to return. |
Property Value
Key
Gets a unique string key that identifies the collection instance.
public string Key { get; }
Property Value
- string:
A unique string key that identifies the collection instance.
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 |
GetEnumerator()
Retrieves an IEnumerator
object for the entire collection.
public IEnumerator<Range> GetEnumerator()
Returns
- IEnumerator<Range>:
An
IEnumerator
object for the entire collection
Remarks
Enumerators are intended to be used only to read data in the collection. Enumerators cannot be used to modify the underlying collection.
The enumerator does not have exclusive access to the collection.
When an enumerator is instantiated, it takes a snapshot of the current state of the collection.
If changes are made to the collection, such as adding, modifying or deleting elements, the
snapshot gets out of sync and the enumerator throws an InvalidOperationException
.
Two enumerators instantiated from the same collection at the same time can have
different snapshots of 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
OverlapsWith(Range)
public bool OverlapsWith(Range range)
Parameter | Type | Description |
---|---|---|
range | Range | The Range to examine. |
Returns
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. |