GetViewBetweenメソッドで指定した範囲外の値をサブセットに対して追加しようとした場合、ArgumentOutOfRangeExceptionがスローされます。 GetViewBetweenメソッドで取得したサブセットに対しては、その範囲内に対する変更のみが行えます。
GetViewBetweenメソッドで指定した範囲外に変更を加えようとするとArgumentOutOfRangeExceptionとなる
using System;
using System.Collections.Generic;
class Sample {
static void Main()
{
var s = new SortedSet<string>() {"Alice", "Eve", "Charlie", "Bob", "Dave"};
// 最小で"B"、最大で"E"の範囲に該当する部分集合を取得する
var view = s.GetViewBetween("B", "E");
// ビューの範囲外の値を追加しようとする
view.Add("Adams");
}
}
実行結果
Unhandled exception. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'item') at System.Collections.Generic.SortedSet`1.TreeSubSet.AddIfNotPresent(T item) at System.Collections.Generic.SortedSet`1.Add(T item) at Sample.Main() in /home/smdn/samplecodes/dotnet/cs/test.cs:line 13