Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ bool ICollection<T>.IsReadOnly

#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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,17 @@ public void ICollectionMethods()
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]);
}
}
}