Skip to content

Commit c90807a

Browse files
authored
Fix potential IndexOutOfRangeException (dotnet#8201)
1 parent b130de5 commit c90807a

File tree

1 file changed

+1
-1
lines changed
  • snippets/csharp/System.Collections.Generic/ICollectionT/Overview

1 file changed

+1
-1
lines changed

snippets/csharp/System.Collections.Generic/ICollectionT/Overview/program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void CopyTo(Box[] array, int arrayIndex)
198198
throw new ArgumentNullException("The array cannot be null.");
199199
if (arrayIndex < 0)
200200
throw new ArgumentOutOfRangeException("The starting array index cannot be negative.");
201-
if (Count > array.Length - arrayIndex + 1)
201+
if (Count > array.Length - arrayIndex)
202202
throw new ArgumentException("The destination array has fewer elements than the collection.");
203203

204204
for (int i = 0; i < innerCol.Count; i++) {

0 commit comments

Comments
 (0)