This commit is contained in:
Nick Guerrera 2014-11-11 14:47:25 -08:00
Родитель ce3f774426 89c99b789d
Коммит 0a4d5472f3
2 изменённых файлов: 26 добавлений и 0 удалений

Просмотреть файл

@ -97,6 +97,20 @@ namespace System.Collections.Immutable
#endregion
/// <summary>
/// Gets the element of the set at the given index.
/// </summary>
/// <param name="index">The 0-based index of the element in the set to return.</param>
/// <returns>The element at the given position.</returns>
/// <remarks>
/// No index setter is offered because the element being replaced may not sort
/// to the same position in the sorted collection as the replacing element.
/// </remarks>
public T this[int index]
{
get { return this.root[index]; }
}
/// <summary>
/// Gets the maximum value in the collection, as defined by the comparer.
/// </summary>

Просмотреть файл

@ -313,5 +313,17 @@ namespace System.Collections.Immutable.Test
Assert.NotNull(builder.SyncRoot);
Assert.Same(builder.SyncRoot, builder.SyncRoot);
}
[Fact]
public void Indexer()
{
var builder = ImmutableSortedSet.Create(1, 3, 2).ToBuilder();
Assert.Equal(1, builder[0]);
Assert.Equal(2, builder[1]);
Assert.Equal(3, builder[2]);
Assert.Throws<ArgumentOutOfRangeException>(() => builder[-1]);
Assert.Throws<ArgumentOutOfRangeException>(() => builder[3]);
}
}
}