Skip to content

Commit

Permalink
Fix Hashtable.CopyTo (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
NemesisXB authored and josesimoes committed Sep 12, 2018
1 parent d9e569d commit de45317
Showing 1 changed file with 10 additions and 6 deletions.
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

0 comments on commit de45317

Please sign in to comment.