Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hashtable.CopyTo #23

Merged
merged 3 commits into from
Sep 12, 2018
Merged
Changes from 2 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
16 changes: 10 additions & 6 deletions source/System/Collections/HashTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ private void Rehash(int newSize)
//implementation for KeyCollection and ValueCollection copyTo method
private void CopyToCollection(Array array, int index, EnumeratorType type)
{
if (index < 0 && index > _numberOfBuckets) throw new IndexOutOfRangeException("index");
if (index < 0 || index >= array.Length) throw new IndexOutOfRangeException("index");
if ((index + Count) > array.Length) throw new IndexOutOfRangeException("array length");

var j = 0;
var j = index;
var len = array.Length;

for (var i = index; i < _numberOfBuckets; i++)
for (var i = 0; i < _numberOfBuckets; i++)
{
for (var cur = _buckets[i]; cur != null && j < len; cur = cur.next)
{
Expand Down Expand Up @@ -229,15 +230,18 @@ public object SyncRoot
/// <param name="index">The zero-based index in array at which copying begins.</param>
public void CopyTo(Array array, int index)
{
if (index < 0 && index > _buckets.Length) throw new IndexOutOfRangeException("index");
if (index < 0 || index >= array.Length) throw new IndexOutOfRangeException("index");
if ((index + _count) > array.Length) throw new IndexOutOfRangeException("array length");

var j = 0;
var j = index;
var len = array.Length;
for (var i = index; i < _buckets.Length; i++)

for (var i = 0; i < _numberOfBuckets; i++)
{
for (var cur = _buckets[i]; cur != null && j < len; cur = cur.next)
{
((IList)array)[j] = new DictionaryEntry(cur.key, cur.value);

j++;
}
}
Expand Down