SortedSet<T>.GetViewBetween(T, T) 方法

定義

傳回 SortedSet<T> 中資料子集的檢視。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);
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)

參數

lowerValue
T

檢視中所需的最小值。The lowest desired value in the view.

upperValue
T

檢視中所需的最大值。The highest desired value in the view.

傳回

SortedSet<T>

子集檢視,只包含指定之範圍內的值。A subset view that contains only the values in the specified range.

例外狀況

根據比較子,lowerValue 大於 upperValuelowerValue is more than upperValue according to the comparer.

在檢視上的嘗試作業,超出指定的 lowerValueupperValue 範圍。A tried operation on the view was outside the range specified by lowerValue and upperValue.

範例

下列範例會使用 GetViewBetween 方法,從一組已排序的媒體檔案名中只列出 AVI 檔案。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. lowerValue是 "AVI",而且 upperValue 只是一個較高的值 "AVJ",以取得所有 AVI 檔案的觀點。The lowerValue is "AVI" and the upperValue is only one value higher, "AVJ", to get the view of all AVI files. 這個程式碼範例是針對類別提供之較大範例的一部分 SortedSet<T>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

備註

這個方法會傳回介於和之間的專案範圍的視圖 lowerValue upperValue ,如比較子所定義。This method returns a view of the range of elements that fall between lowerValue and upperValue, as defined by the comparer. 這個方法不會複製中的專案 SortedSet<T> ,但會將視窗提供給基礎 SortedSet<T> 本身。This method does not copy elements from the SortedSet<T>, but provides a window into the underlying SortedSet<T> itself. 您可以在視圖和基礎中進行變更 SortedSet<T>You can make changes in both the view and in the underlying SortedSet<T>.

適用於