SortedSet<T>.GetViewBetween(T, T) Method

Definition

Returns a view of a subset in a SortedSet<T>.

public:
 virtual System::Collections::Generic::SortedSet<T> ^ GetViewBetween(T lowerValue, T upperValue);
public virtual System.Collections.Generic.SortedSet<T> GetViewBetween (T lowerValue, T upperValue);
abstract member GetViewBetween : 'T * 'T -> System.Collections.Generic.SortedSet<'T>
override this.GetViewBetween : 'T * 'T -> System.Collections.Generic.SortedSet<'T>
Public Overridable Function GetViewBetween (lowerValue As T, upperValue As T) As SortedSet(Of T)

Parameters

lowerValue
T

The lowest desired value in the view.

upperValue
T

The highest desired value in the view.

Returns

A subset view that contains only the values in the specified range.

Exceptions

lowerValue is more than upperValue according to the comparer.

A tried operation on the view was outside the range specified by lowerValue and upperValue.

Examples

The following example uses the GetViewBetween method to list only the AVI files from a sorted set of media file names. The comparer evaluates file names according to their extensions. The lowerValue is "AVI" and the upperValue is only one value higher, "AVJ", to get the view of all AVI files. This code example is part of a larger example provided for the SortedSet<T> class.

// List all the avi files.
SortedSet<string> aviFiles = mediaFiles1.GetViewBetween("avi", "avj");

Console.WriteLine("AVI files:");
foreach (string avi in aviFiles)
{
    Console.WriteLine($"\t{avi}");
}
' List all the avi files.
Dim aviFiles As SortedSet(Of String) = mediaFiles1.GetViewBetween("avi", "avj")
Console.WriteLine("AVI files:")
For Each avi As String In aviFiles
    Console.WriteLine($"{vbTab}{avi}")
Next

Remarks

This method returns a view of the range of elements that fall between lowerValue and upperValue, as defined by the comparer. This method does not copy elements from the SortedSet<T>, but provides a window into the underlying SortedSet<T> itself. You can make changes in both the view and in the underlying SortedSet<T>.

Applies to