зеркало из https://github.com/App-vNext/corefx.git
Merge branch 'SortedSetBuilderIndexer' of https://github.com/AArnott/corefx
This commit is contained in:
Коммит
0a4d5472f3
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче